Published 6 months ago by LSheNNawY
Hi there, I'm trying to validate two files inputs one for a logo and the other for an icon,
1- added the
enctype="multipart/form-data" to the form.
2- validation rules for these inputs are:
[ 'logo' => 'image|mimes:jpeg, jpg, bmp, png', 'icon'=> 'image|mimes:ico', ]
3- when I try to upload a
logo of the type
png, it returns an error says
"The Logo must be a file of type: jpeg, jpg, bmp, png."
4- when I try to upload an
icon of the type
ico it returns error says
"The Icon must be an image."
Try removing the spaces between the mime types in both places
'logo' => 'image|mimes:jpeg,jpg,bmp,png'
When a rule accepts parameters separated by commas, there can't be any spaces in between the values since it will explode() on commas to get the individual parameters and if they have spaces in it then it becomes " jpg" and " png" instead of "jpg" and "png". I don't think it runs trim() on the results.
Notice in the user guide how they don't have spaces: https://laravel.com/docs/5.6/validation#rule-mimes
'photo' => 'mimes:jpeg,bmp,png'
mimes list should be without spaces as far as I know!
Also for images there is a separate validation rule called
image, you don't need
mimes anymore then ;)
ico rule should work as far as I know! Are you sure that image is of the type