Your FormRequest
needs to know that the name field is a array
and the already has a form of validate the field only needs to have the following nomenclature:
>
nome_do_campo
+ .*
Since your fields are related to both, you need to follow the nomenclature nome.*
and liberar.*
in the part of the validation, already in the part of the form ( <form>
) follows example below: p>
<p>
<input type="checkbox" value="true" name="liberar[]">
<input type="text" value="" name="nome[]">
</p>
<p>
<input type="checkbox" value="true" name="liberar[]">
<input type="text" value="" name="nome[]">
</p>
Also see an example of FormRequest
:
class ExemploRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'nome.*' => 'required_if:liberar.*,true'
];
}
public function messages()
{
return [
'nome.required_if' => 'nome é para ser digitado'
];
}
}
Recommendation: You should also control the validation with Javascript
to send the data practically correct, and these fields are sequences be very careful about this. >