My form allows users to add fields to upload a file dynamically.
<input type="file" name="your_file_{{ $i }}" id="your_file_{{ $i }}">
So it generates input names like: your_file_1
, your_file_2
, …
Now I want to make these fields mandatory through validation rules, but I can’t find a way to do that.
I tried with a wildcard but it doesn’t work.
$rules['your_file_*'] = 'required|mimes:pdf,doc,docx,png,jpg,jpeg|max:10000';
Any idea?
2
Answers
To specify a wildcard rule use dot syntax:
.*
-1 is for token csrf in post, total loop is for only dinamic input.
For loop in Laravel validation
here for references