User registration with CPF or CNPJ Laravel 5.5

1

How do I custom validate user registration for Laravel on auth default using php artisan make:auth ?

I need the following clause It is mandatory to enter the field CPF or CNPJ .

I found the validation of the registry, but, would you like to add this clause?

return Validator::make($data, [
        'name' => 'required|string|max:255',
        'email' => 'required|string|email|max:255|unique:users',
        'password' => 'required|string|min:6|confirmed',
    ]);
    
asked by anonymous 14.02.2018 / 11:34

1 answer

1

Take a look at the documentation: link

required_with: foo, bar, ... The field under validation must be present and not empty only if any of the specified fields are present.

required_with_all: foo, bar, ... The field under validation must be present and not empty only if all of the specified fields are present.

required_without: foo, bar, ... The field under validation must be present and not empty when any of the specified fields are not present.

required_without_all: foo, bar, ... The field under validation must be present and not empty when all of the specified fields are not present.

Maybe this will work (did not test)

$validator = \Validator::make(["cnpj"=>123, "cpf"=>123],[
        "cpf"   => "required_without_all:cnpj",
        "cnpj"  => "required_without_all:cpf"
    ]);
    
17.02.2018 / 03:45