Validate Multiple Images Field I have a multiple images field in my form where there I want Laravel to validate the following:
a) Maximum images uploaded at a time should not exceed more than 20
b) Each image uploaded should be -- jpeg,png or gif and the image should not exceed 4MB in size.
I added the following validation rules however they do not work
'images.*' => 'bail|mimes:jpeg,png,gif|size:4096',
'images' => 'bail|array|max:20',
Laravel confuses itself with max and size.
Well, if you use bail bail , when the first validation fail it will stop checking the other fields.
So, the order is important here check the size of the array images first!,
'images' => 'bail|array|max:20',
'images.*' => 'bail|mimes:jpeg,png,gif|size:4096',
@PSYLOGIC - Hi,
I have tried this but it still does not work.
Changed the rule to
'images' => 'array|max:20',
'images.*' => 'mimes:jpeg,png,gif|size:4096',
'images.max' => 'You cannot upload more than 20 images for this listing',
'images.*.mimes' => 'Only JPEG, PNG and GIF images are allowed',
'images.*.size' => 'Uploaded image cannot be more than 4 MB in size',
But it still does not work. I am now getting the error as:
Error — Uploaded image cannot be more than 4 MB in size
Please sign in or create an account to participate in this conversation.