How to validate at least one required field?

3

I have two fields CPF and CNPJ, the user must enter only one, but never leave both fields empty. This way it leaves the two fields mandatory:

 [
   'Cpf' => array('required'),
   'Cnpj' => array('required'),
 ]

Is there any way in Laravel to validate only one required field when one is filled in?

    
asked by anonymous 12.01.2017 / 14:14

1 answer

3

You can use required_without or required_without_all .

[
    'Cpf'  => 'required_without:Cnpj',
    'Cnpj' => 'required_without:Cpf',
]
    
12.01.2017 / 14:36