I am currently working in a form.
I have some issue with multiple file upload validation. I have only one field in a form which allows multiple file upload.
<input type="file" name="file[]" multiple="multiple">
And this is my validation,
$this->validate($request, [
'file' =>'required',
'file.*' => 'required|mimes:pdf,jpeg,png |max:4096',
],
$messages = [
'mimes' => 'Only PDF, JPEG, PNG are allowed.'
]
);
The validation works perfectly but I am not able to display error messages in blade file.
Here are my attempts.
@if($errors->has('file'))
<span class="help-block">
<strong>{{$errors->first('file')}}</strong>
</span>
@endif
This is for displaying error if no file is uploaded.
Suppose I have uploaded following files,
abc.jpg
abc.html
abc.pdf
When mimes type validation throws error I am not able to display error message.
Here in this case, error is thrown as $error->first(file.1) since validation fails at index 1
This index can be any index according to files uploaded and $error->first(file.*) doesn't work as well.
When I display all error after adding invalid files only from form, I've got these errors.
Only PDF, JPEG, PNG are allowed.
The type field is required.
The number field is required.
The expiry date field is required.
Any one have idea about this. Any help is appreciated.
Thanks,