Hi @bojan1994
Check that you have included enctype="multipart/form-data” to your form.
Hi,
I have a problem with validation of multiple file uploads. I have two inputs in form, documentFile (which is type="file") and documentName (which is type="text") and user can add more rows by clicking on add button. I have done many array validations before without a problem but now i'm missing something. I succeeded to validate second field easily, but first always passes. Strange thing is, when i modify first input to be type="text" rather then type="file", everything works.
Here's the code:
DocumentationRequest.php
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'documentFile.*' => ['required'],
'documentName.*' => ['required'],
];
}
/**
* Custom messages.
*
* @return array
*/
public function messages()
{
return [
'documentFile.*.required' => __('beneficiary.DocumentFileRequired'),
'documentName.*.required' => __('beneficiary.NameRequired'),
];
}
form.blade.php
<div class="row" id="documentation-body-row-0">
<div class="col-lg-6">
<p class="mb-2">
<span class="text-danger">*</span> {{ __('beneficiary.Document') }}
</p>
<div class="custom-file">
<input type="file"
class="form-control @if($errors->has('documentFile.*')) is-invalid @endif"
id="documentFile[0]"
name="documentFile[0]">
<label class="custom-file-label"
for="documentFile[0]">{{ __('beneficiary.SelectDocument') }}
</label>
</div>
@error('documentFile.*')
<div class="invalid-feedback d-block">
{{ $message }}
</div>
@enderror
</div>
<div class="col-lg-6 form-group">
<label for="documentName[0]">{{ __('beneficiary.Name') }}</label>
<input type="text"
name="documentName[0]"
id="documentName[0]"
class="form-control @if($errors->has('documentName.*')) is-invalid @endif">
@error('documentName.*')
<div class="invalid-feedback d-block">
{{ $message }}
</div>
@enderror
</div>
</div>
Please or to participate in this conversation.