@kfirba Your input name = "image", and you validate "image". So I suppose you should try dd($request->file('image')), and get image field is required in the message.
Sep 6, 2016
8
Level 50
validating uploaded file always fails
Hey.
I got a form that have an input for a file. When I submit the form, I validate that the a photo was uploaded by using the following rule:
'image' => 'required|mimes:jpg,jpeg,png,bmp'
My input field code is:
<div class="form-group row{{ $errors->has('image') ? ' has-danger' : '' }}">
<label for="photo" class="col-sm-2 col-form-label"><strong>Image</strong></label>
<div class="col-sm-10">
<input id="photo" class="form-control-file" type="file" name="image">
@if ($errors->has('image'))
<div class="form-control-feedback">
<strong>{{ $errors->first('image') }}</strong>
</div>
@endif
</div>
</div>
The form contains the enctype="multipart/form-data" attribute so it should upload the file.
90% of the times when I submit the form, I get the error validation message The photo field is required.. The other 10% of the times it somehow works... I really don't know what's going on..
I tried to dd($request->file('photo')) and I get an instance of UploadedFile. Why validation fails then?
Does anyone have an idea what's going on here?
Please or to participate in this conversation.