在 Laravel 5.7 中,我正在使用表单请求验证:
public function rules()
{
return [
'age' => 'integer',
'title' => 'string|max:50'
];
}
如果我使用这个有效载荷向我的API提交请求:{
"age": 24,
"title": ""
}
Laravel返回错误:
{
"message": "The given data was invalid.",
"errors": {
"title": [
"The title must be a string."
]
}
}
我希望这个验证能够通过,因为标题是一个字符串,即使是空字符串。该如何设计验证规则以允许空字符串?
present
或required
验证器。 - ka_lin