jeudi 18 juin 2020

Is there a required_without_all validator but for checkbox in Laravel?

I have a form that can contain multiple items and for each item, there is multiple checkboxes and I want to validate if any of those checkboxes are checked.

My form looks like this for each item.

<div class="row">
<label for="form-123-option1">Options 1</label>
<input id="form-123-option1" type="checkbox" name="item[123][option1]"/>
</div>
<div class="row">
<label for="form-123-option2">Options 2</label>
<input id="form-456-option2" type="checkbox" name="item[456][option2]"/>
</div>

And I've got about 8 of those checkboxes. They correspond to bool field in the database. Each item in the database have 8 boolean field.

I've already tried this solution, but my form gets validated even if none of the checkboxes are checked:

'checkbox1' => 'required_without_all: checkbox2, checkbox3,checkbox4',
'checkbox2' => 'required_without_all: checkbox1, checkbox3,checkbox4',
'checkbox3' => 'required_without_all: checkbox1, checkbox2,checkbox4',
'checkbox4' => 'required_without_all: checkbox1, checkbox2,checkbox3'

What would be the best way to validate if any of the 8 fields is checked in Laravel?




Aucun commentaire:

Enregistrer un commentaire