Download the PHP package singra/laravel-br-validation without Composer

On this page you can find all versions of the php package singra/laravel-br-validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-br-validation

singra/laravel-br-validation

English · Português

The Laravel bridge for singra/br-validation: validation rules with localised messages, Eloquent casts, and Faker providers for CPF, CNPJ and CEP.

The document logic lives upstream and is not restated here. What this package adds is the part that is genuinely Laravel's: a rule that speaks the user's language, a cast that turns a column into a value object, and a fake()->cpf() that survives its own validation.

Laravel 12 and 13, PHP 8.3+. Auto-discovered — there is nothing to register.

Quick start

Rules

Each document has a rule object and a string rule. They are the same rule — same verdict, same message — and the test suite asserts it rather than assuming it.

Document Rule object String rule
CPF Rules\CpfRule cpf
CNPJ Rules\CnpjRule cnpj
CEP Rules\CepRule cep

The rules carry the Rule suffix that Laravel's own do not, because the thing being validated is already called Cpf. A controller that validates input and then builds the value object needs both names in scope.

A value that is already a Cpf, Cnpj or Cep instance passes without being re-checked. Holding one is proof the check digits were verified when it was built, so validating it again would only re-derive a fact already established.

null

Without nullable, null fails — Laravel's convention is that nullable is what grants permission to omit an answer, and it skips the rule outright when present.

Integers

An integer is refused rather than read as a string.

012.345.678-90 is a valid CPF, and out of an INT column or a JSON number it arrives ten characters long. Repairing that belongs at the boundary where the data was damaged, not in a rule that would then appear to vouch for a value it guessed at.

Messages

Shipped in English and Brazilian Portuguese, and rendered in the application's current locale. Three messages per document, not five.

Reason cpf message (en)
WrongLength The document field must have 11 digits.
IllegalCharacter The document field must contain digits only.
RepeatedCharacters InvalidCheckDigit UnallocatedRange The document field must be a valid CPF.

Only length and alphabet tell the person at the keyboard something they can act on. "The check digits do not match" and "every character is the same" both mean, to them, an invalid CPF — which is why Brazilian government portals render them the same way. Code that needs the distinction should catch InvalidDocument and read its reason, exactly as the upstream README describes.

CEP is the one where the collapsed message earns its own wording: with no check digit, a rejection means the code belongs to no block Correios ever allocated. It does not exist rather than fails, and the message says so.

Overriding a message

Everything Laravel already offers works, in its usual order of precedence:

To change them globally, publish the language files:

That writes lang/vendor/br-validation/{en,pt_BR}/validation.php. Add a locale by dropping a directory beside them; nothing else needs changing.

:attribute is left in the message for Laravel to substitute, so validation.attributes and custom attribute names apply as they do anywhere else.

Casts

Stored unpunctuated — eleven characters for CPF, fourteen uppercase for CNPJ, eight for CEP. Punctuation stays a display decision made on the way out, so a CHAR(11) column never receives a mask by accident.

Writing accepts either a string or the value object, and validates both:

Reading a row that does not validate

It throws. This is the same bargain Laravel's own enum cast strikes with ValueError, and it is deliberate. Returning null would be indistinguishable from an empty column, so a bad legacy row would read as missing data — and the day you noticed would be the day something had already overwritten it.

If a table holds documents entered before anything validated them, do not cast the column. Cpf::mask() renders those without vouching for them:

CEP is the likeliest to trip on legacy data, because its validation includes the Correios allocation table: a code vacated by the Rondônia renumbering was a real CEP when the row was written and is not one now.

Faker

Registered for every locale, so fake() works whatever app.faker_locale is set to. Generated documents pass this package's own rules — a generated CEP is drawn from the allocation table rather than being eight random digits.

Two differences from Faker's built-in pt_BR provider, which this one shadows:

  1. Output is unpunctuated by default, where Faker's cpf() and cnpj() default to formatted. A generated document is nearly always on its way into a column. Pass formatted: true for the mask.
  2. cnpj() can generate the post-2026 alphanumeric format, and cep() exists.

Output is reproducible under fake()->seed(). Faker seeds mt_srand() while the generators upstream take a Random\Randomizer, and the package bridges the two so that a seeded suite can reproduce its own failures. That bridge is for fixtures only; Cpf::generate() with no argument uses the CSPRNG.

Not included

Versioning and support

Strict SemVer. The previous major receives bug fixes and security fixes for 12 months after its successor ships, then is archived.

Development

Coverage needs Xdebug or PCOV. Tests run against a real Laravel application via Orchestra Testbench, and the casts through a real Eloquent write and read — the interesting failures live in the round trip.

The one rule worth knowing before changing anything: rules, casts and the string rules all reduce to Support\Document. That single seam is why the three spellings cannot drift into disagreeing about what a CPF is, and the suite asserts the agreement rather than trusting it.

License

MIT. See LICENSE.


All versions of laravel-br-validation with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^12.0 || ^13.0
illuminate/database Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.0
illuminate/validation Version ^12.0 || ^13.0
singra/br-validation Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package singra/laravel-br-validation contains the following files

Loading the files please wait ...