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?
for($i = 1; $i <= count($request->all()) - 1; $i++) {
$validate_array['var'. $i] = 'required';
}
$this->validate($request, $validate_array );
-1 is for token csrf in post, total loop is for only dinamic input.
For loop in Laravel validation
here for references