How to validate image in Laravel

Viewed 2040

I am trying laravel image validation for the following field-

<label class="btn btn-success">
    <input name="image" type="file"/>Add Image</label>
    @if ($errors->has('image'))
       <span class="alert alert-danger">
          {{ $errors->first('image') }}
       </span>
    @endif

And my validation rule is written like this-

$request->validate([
  'image'=> 'mimes:jpeg,jpg,png,gif|max:1000',
]);

But no matter what whether I give a valid image as input or not my validation rule gives me this error-

The image must be a file of type: jpeg, jpg, png, gif.

You can consider me beginner in laravel and I cant really find out what I am doing wrong here. Can anyone help?

1 Answers
Related