lumensistemas/laravel-br-validation

Laravel integration for lumensistemas/br-validation: Rule classes and named validators for Brazilian identifiers (CPF, CNPJ, PIS, Título de Eleitor, CNH, Renavam, placa, CNS, chave PIX, CEP, telefone, boleto, NF-e).

Maintainers

Package info

github.com/lumensistemas/laravel-br-validation

pkg:composer/lumensistemas/laravel-br-validation

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-05-17 12:33 UTC

This package is auto-updated.

Last update: 2026-05-17 12:53:06 UTC


README

Tests Latest Stable Version Total Downloads

Laravel integration for lumensistemas/br-validation. Ships Illuminate\Contracts\Validation\ValidationRule classes and matching string-named rules (cpf, cnpj, pis, …) for every Brazilian identifier the underlying library covers.

Requirements

  • PHP 8.3 or newer
  • Laravel 12 or 13
  • ext-mbstring

Installation

composer require lumensistemas/laravel-br-validation

The service provider is auto-discovered. Publish the translations if you want to override them:

php artisan vendor:publish --tag=laravel-br-validation-lang

Usage

As string-named rules

$request->validate([
    'cpf'              => ['required', 'cpf'],
    'cnpj'             => ['required', 'cnpj'],
    'pis'              => ['nullable', 'pis'],
    'titulo_eleitor'   => ['nullable', 'titulo_eleitor'],
    'cnh'              => ['nullable', 'cnh'],
    'renavam'          => ['nullable', 'renavam'],
    'placa'            => ['nullable', 'placa'],
    'cns'              => ['nullable', 'cns'],
    'chave_pix'        => ['nullable', 'pix'],
    'cep'              => ['required', 'cep'],
    'telefone'         => ['required', 'phone_br'],
    'boleto'           => ['required', 'boleto'],
    'nfe'              => ['required', 'nfe'],
]);

As Rule classes

use LumenSistemas\LaravelBrValidation\Rules\Cpf;
use LumenSistemas\LaravelBrValidation\Rules\Pix;

$request->validate([
    'cpf'   => ['required', new Cpf()],
    'chave' => ['required', new Pix(types: ['email', 'phone'])],
]);

Pix accepts an optional types array to restrict accepted chave PIX types (cpf, cnpj, email, phone, evp); when omitted, all five types are accepted.

Translations

Messages ship in en and pt_BR. Override per locale by publishing the language files:

php artisan vendor:publish --tag=laravel-br-validation-lang

Development

composer install
composer test

License

MIT. See LICENSE.