Registration of users with CPF or CNPJ Laravel 5.5

Asked

Viewed 905 times

1

How do I customize the user registration Laravel in the auth pattern using php artisan make:auth?

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

I found the registration validation, but I’d 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',
    ]);
  • What’s the question? It’s not just enter the validation data in Validator and ready?

  • How to use connective OR ? In validation, to accept only one OR another

1 answer

1

Take a look at the documentation: https://laravel.com/docs/5.5/validation

required_with:foo,,... The field under validation must be present and not Empty only if any of the other specified Fields are present.

required_with_all:foo,,... The field under validation must be present and not Empty only if all of the other specified Fields are present.

required_without:foo,,... The field under validation must be present and not Empty only when any of the other specified Fields are not present.

required_without_all:foo,,... The field under validation must be present and not Empty only when all of the other specified Fields are not present.

Maybe it works that way (I haven’t tested)

$validator = \Validator::make(["cnpj"=>123, "cpf"=>123],[
        "cpf"   => "required_without_all:cnpj",
        "cnpj"  => "required_without_all:cpf"
    ]);
  • I get the following message using the way you gave me, I tested all the other methods but I haven’t got it yet! <code>

  • I get the following message using the way you gave me, I tested all the other methods but I haven’t got it yet! &#xA;O campo cnpj não é um CNPJ válido&#xA;É pq no campo de cnpj e cpf eu tenho a validação personalizada de cnpj e cpf &#xA;<code>&#xA;'cpf' => '|cpf|required_if:cnpj,0|unique:clientes,cpf',&#xA; 'cnpj' => '|cnpj|required_if:cpf,0|unique:clientes,cnpj',&#xA;</code>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.