1
votes

I have some problems with Laravel Validator. I'm sending some images as an array, and it's validating images even if they are empty, but they are not required, it always says that The images must be an image, and The images must be a file of type: jpg, png, jpeg, gif, svg. I have specified that images are array and nullable, but still have this problem. Here is my validation for images.

'images*' => 'array|nullable|image|mimes:jpg,png,jpeg,gif,svg',

Any ideas how to fix it?

1
Hi, do you have the chance to print the whole request (or try to get the value of that field)? just to be sure that your frontend is not passing a value for that (even undefined could be converted to a string, which is not a valid image). - Lorenzo S

1 Answers

1
votes

I think validation should be like this, you're missing dot between images and *:

'images' => 'array|nullable',
'images.*' => 'image|mimes:jpg,png,jpeg,gif,svg',