Level 67
I believe the messages should be in the format of fieldName.ruleName:
'file.required' => 'An image file is required',
'file.max' => 'The file size should be less than 1MB!',
// ...
1 like
I'm trying add custom error messages for image validations:
$this->validate($request, [
'file' => 'required|max:1000|file|image|dimensions:max_width=200,max_height=60,min_width=75'
]);
How can I add custom messages for each validations?
I tried something like this:
$messages = [
'required' => 'An image file is required!',
'max' => 'The file size should be less than 1MB!',
'image' => 'The file has to be an image file!',
'dimensions:max_width' => 'The image cannot be wider than 200px!',
'dimensions:min_width' => 'The image cannot be shorter than 75px in width!',
'dimensions:min_height' => 'The image should be less than 60px in height!',
];
$this->validate($request, [
'file' => 'required|max:1000|file|image|dimensions:max_width=200,max_height=60,min_width=75'
], $messages);
and it didn't work I guess.
Please or to participate in this conversation.