How to implement a validation rule in Laravel?

Asked

Viewed 4,276 times

2

I would like to know how to validate a rule in the Auth form.

In this case, it is a CPF rule. The validation rules and error messages I already have, but I don’t know how to implement in the framework.

I must put the rules directly in the Controller Validator?

2 answers

1

I don’t know any native form of the Laravel to do this validation, I’ve worked on a project where I needed to validate Cpf and phone and the way was to use a library that is available on github in the following link:

https://github.com/LaravelLegends/pt-br-validator

You can install via adding Composer:

{
    "laravellegends/pt-br-validator" : "5.1.*"
}

In the link mentioned above you have all the tips on how to use the library!

  • 2

    Thank you for quoting my library :)

0

I state the following repository to be installed in your Laravel project:

https://github.com/geekcom/validator-docs

  • The main advantage of this specific project, that you can validate the CPF or CNPJ in the same field. Follow:

    $this->validate($request, [ 'cpf_or_cnpj' => 'formato_cpf_cnpj|cpf_cnpj', ]);

  • Excellent documentation.

Browser other questions tagged

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