one email is required. and one checkbox should be checked in the first row.
if the second email input is filled in the second row then there is also one checkbox should be checked and so on.
@for ($i = 0; $i < 4; $i++)
<input type="email" id="email" name="email[]">
<input type="checkbox" name="task[{{ $i }}][]" value="sign">
<input type="checkbox" name="task[{{ $i }}][]" value="initial">
<input type="checkbox" name="task[{{ $i }}][]" value="date">
<input type="checkbox" name="task[{{ $i }}][]" value="cc"
@endfor
this is the code in my controller its not catch the task field if it’s null.
$validatedData = $request->validate([
'email.0' => 'required_without_all:email.*|email',
'email.1' => 'nullable|email',
'email.2' => 'nullable|email',
'email.3' => 'nullable|email',
'task.*' => 'required_if:email.*,filled',
]);
3
Answers
I have searched a lot everywhere but the following code worked for me:
You can try this
First, change the field name like below
Here I used
data
as an array index in order to map theemail
,sign
,date
, andinitial
fields under the same indexOnce you pass
email
in the first box and select theinitial
option and keep the rest unchanged and adddd($request->all())
in the controller you will output as given below.Now add Laravel validation with the given below
This will validate the form data both ways around.
NOTE: You must add some custom validation to check if non of the values are selected.
I hope you find this helpful.
}
Here, I have full control of validation rules