Paul Lucero Paul Lucero - 2 months ago 33
PHP Question

LARAVEL VALIDATION ALLOW IMAGE OR PDF

I have a file input in Laravel and I would like it to only allow images or pdf. How do I do this in controller validation?

$validator = Validator::make($request->all(), [
'image' => 'image',
]);

Answer

You should rather make a MIME type validation:

$validator = Validator::make($request->all(), [
    'image' => 'mimes:jpeg,bmp,png,gif,svg,pdf',
]);
Comments