Issue
In Laravel 5.7 I am using form request validation:
public function rules()
{
return [
'age' => 'integer',
'title' => 'string|max:50'
];
}
If I submit a request to my API with this payload:
{
"age": 24,
"title": ""
}
Laravel returns the error:
{
"message": "The given data was invalid.",
"errors": {
"title": [
"The title must be a string."
]
}
}
I would expect it to pass the validation, since the title is a string, albeit an empty one. How should the validation be formulated to allow empty strings?
Solution
Try to see if ConvertEmptyStringsToNull
middleware is active then it would explain this behavior, see docs
Answered By - ka_lin
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.