Reputation: 15057
I have a form for files uploading and there are 2 input fields for each file ([upload] and [expiration_date])
I don't know how to use the laravel required_if validation rule because of this array brackets. So for example if a file is chosen the expiration date should be filled and if there is no file then expiration date doesn't matter.
i have this rules now:
$rules = [
'upload.*' => 'file|max:5120|mimes:pdf,jpeg,jpg,png,gif',
'expiration_date.*' => 'required_if:upload:??????????'
];
<input type="file" name="upload[]"/><label for="expiration_date">Gültig bis: *</label>
<input name="expiration_date[]" type="text">
How to validate expiration_date if file is chosen?
Upvotes: 0
Views: 1417
Reputation: 3795
You need to use the required_with
rule, not required_if
.
$rules = [
'upload.*' => 'file|max:5120|mimes:pdf,jpeg,jpg,png,gif',
'expiration_date.*' => 'required_with:upload.*|date'
];
I also added the date
rule as it's a date.
Upvotes: 2