I have a request class called PessoaRequest
. In this class, I validate my registration form for people.
But now, some information to be inserted appears that is not mandatory: the name of the father and the mother. When I have this information, I set a checkbox
that creates the html fields to enter this data.
In class PessoaRequest
, I have the following rules:
return [
'name' => 'required|min:3|alpha', //obrigatório com pelo menos 3 caracteres alfabéticos
'telefone_1' => 'required',//obrigatório e deve ser um email
'email' => 'required'
[....]
];
In it, I can not place a rule for the fields that ask for the name of the father and the mother, since they are not mandatory.
I would like to know if you can put conditional rule inside Request
, type:
// Se o checkbox for marcado
if($chkPais == 1 ) {
'nome_pai' => 'required',
'nome_mae' => 'required'
}
If not, how could you do this validation?
Thank you in advance.