I want to validate a file input
but the validation does not work it always return The given data was invalid.
even if the file given meets the validation requirements knowing that I'm uploading multiple files at once:
Here's the validation I use :
Validator::make($request->all('files'), [
'files' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'
])->validate();
And here's the HTML I use :
<input type="file" id="files" ref="files" multiple v-on:change="uoloadFiles()" name="files"/>
Knowing that I use vue to handle the form submission.
Thanks for helping
This should work since you are uploading multiple files, each file should be validated separately.
Validator::make($request->all('files'), [
'files.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'
])->validate();
Note the *
.
Further reference here
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