specify the mime types you want to allow
Jan 5, 2021
6
Level 9
File(docx,pdf) and image(jpeg,png etc..) support validation laravel
In my form I have a file upload tag....but I want to both type of file upload support such as user can upload pdf,docx,image aswell. Can anyone tell me what validation I have to make...?
This is my validation
$validatedData = $this->validate([
'product_name' => 'required',
'images.*' => 'image|max:1024',
]);
Level 48
Hi @neeraj1005
Image
The file under validation must be an image (jpg, jpeg, png, bmp, gif, svg, or webp).
https://laravel.com/docs/8.x/validation#rule-image
You can use a MIME Rule and add the validation mime types from the image validation.
$validatedData = $this->validate([
'product_name' => 'required',
'images.*' => 'mimes:jpg,jpeg,png,bmp,gif,svg,webp,pdf,docx|max:1024',
]);
https://laravel.com/docs/8.x/validation#basic-usage-of-mime-rule
1 like
Please or to participate in this conversation.