I need to validate that a user only uploads a .jpg
I have the following request class. I made the image required but don't know how to check that it is only .jpg
public function rules()
{
return [
'name' => 'required|min:3',
'sku' => 'required|min:5|unique:products',
'description' => 'required|min:20',
'price' => 'required',
'image' => 'required'
];
}
Does it have to just be .jpg? If so then something like:
'image' => 'required|mimes:jpeg'
Documentation: http://laravel.com/docs/5.1/validation#rule-mimes
If it can be any type of image, then:
'image' => 'required|image'
Documentation: http://laravel.com/docs/5.1/validation#rule-image
laravel 8
\request ()->validate(['photo' => 'mimes:jpg,bmp,png']);
official documentation link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With