PHPackages                             cavalheri/laravel-brazil-documents - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. cavalheri/laravel-brazil-documents

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

cavalheri/laravel-brazil-documents
==================================

Validation, formatting, sanitization and generation of Brazilian documents for Laravel.

v1.4.0(2w ago)231MITPHPPHP ^8.3CI passing

Since May 23Pushed 2w agoCompare

[ Source](https://github.com/LucasCavalheri/laravel-brazil-documents)[ Packagist](https://packagist.org/packages/cavalheri/laravel-brazil-documents)[ RSS](/packages/cavalheri-laravel-brazil-documents/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (6)Versions (13)Used By (0)

Laravel Brazil Documents
========================

[](#laravel-brazil-documents)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0ac39937eb67e0983e6b9da73d14f04a34fff2b3b48612b6532c71052a88e983/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636176616c686572692f6c61726176656c2d6272617a696c2d646f63756d656e74732e737667)](https://packagist.org/packages/cavalheri/laravel-brazil-documents)[![Total Downloads](https://camo.githubusercontent.com/ec1c85c2f9468f7bfc6e50dc885c3b688b1894fd7ec191fd799738f604dd73e0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636176616c686572692f6c61726176656c2d6272617a696c2d646f63756d656e74732e737667)](https://packagist.org/packages/cavalheri/laravel-brazil-documents)[![License](https://camo.githubusercontent.com/36e1a9e63cc1e38623470dd5628ee511029a03b416a13ee163a78b448e45eee8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636176616c686572692f6c61726176656c2d6272617a696c2d646f63756d656e74732e737667)](https://packagist.org/packages/cavalheri/laravel-brazil-documents)[![Tests](https://github.com/LucasCavalheri/laravel-brazil-documents/actions/workflows/tests.yml/badge.svg)](https://github.com/LucasCavalheri/laravel-brazil-documents/actions/workflows/tests.yml)[![Documentation](https://github.com/LucasCavalheri/laravel-brazil-documents/actions/workflows/docs.yml/badge.svg)](https://github.com/LucasCavalheri/laravel-brazil-documents/actions/workflows/docs.yml)

An elegant, Laravel-first toolkit for validating, formatting, sanitizing, and generating Brazilian documents.

Includes **CPF**, **CNPJ**, **CEP**, **CNH**, **PIS/PASEP**, **CNS**, and **Título de eleitor**. Current version: **1.4.0** (see [`VERSION`](VERSION)). The architecture is prepared for future document types.

**Author:** [Lucas Cavalheri](https://lucascavalheri.com.br) · [GitHub](https://github.com/LucasCavalheri) · [LinkedIn](https://linkedin.com/in/lucas-cavalheri)

**Install via Composer:** [packagist.org/packages/cavalheri/laravel-brazil-documents](https://packagist.org/packages/cavalheri/laravel-brazil-documents)

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 13.x

Documentation
-------------

[](#documentation)

Hosted on [Vercel](https://vercel.com):

- **pt-BR (default):** [laravel-brazil-documents.lucascavalheri.com.br](https://laravel-brazil-documents.lucascavalheri.com.br)
- **English:** [/en/](https://laravel-brazil-documents.lucascavalheri.com.br/en/)

Local preview:

```
npm install
npm run dev
```

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for release notes.

Installation
------------

[](#installation)

Published on [Packagist](https://packagist.org/packages/cavalheri/laravel-brazil-documents):

```
composer require cavalheri/laravel-brazil-documents
```

The package supports Laravel auto-discovery. No manual registration is required.

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=brazil-documents-config
```

```
return [
    'helpers' => true,
    'locale' => null,
];
```

- **helpers** — Registers global `cpf()`, `cnpj()`, `cep()`, `cnh()`, `pis()`, `cns()`, and `tituloEleitor()` helpers when `true`.
- **locale** — Overrides the locale used for validation messages. When `null`, Laravel's current locale is used.

Quick Start
-----------

[](#quick-start)

### Facade

[](#facade)

```
use Cavalheri\LaravelBrazilDocuments\Facades\BrazilDocuments;

BrazilDocuments::cpf('12345678909')->isValid();
BrazilDocuments::cpf('12345678909')->format();
BrazilDocuments::cpf('123.456.789-09')->sanitize();
BrazilDocuments::cpf()->generate();

BrazilDocuments::cnpj('11222333000181')->isValid();
BrazilDocuments::cep('01001000')->format();
BrazilDocuments::cnh('12345678900')->isValid();
BrazilDocuments::cnh()->generate();

BrazilDocuments::pis('12056413177')->isValid();
BrazilDocuments::pis('12056413177')->format();

BrazilDocuments::cns('279802393660003')->isValid();
BrazilDocuments::cns('279802393660003')->format();

BrazilDocuments::tituloEleitor('825169091279')->isValid();
BrazilDocuments::tituloEleitor('825169091279')->format();
```

### Support classes

[](#support-classes)

```
use Cavalheri\LaravelBrazilDocuments\Support\Cpf;
use Cavalheri\LaravelBrazilDocuments\Support\Cnpj;
use Cavalheri\LaravelBrazilDocuments\Support\Cep;
use Cavalheri\LaravelBrazilDocuments\Support\Cnh;
use Cavalheri\LaravelBrazilDocuments\Support\Pis;
use Cavalheri\LaravelBrazilDocuments\Support\Cns;
use Cavalheri\LaravelBrazilDocuments\Support\TituloEleitor;

Cpf::isValid('12345678909');
Cpf::format('12345678909');
Cpf::sanitize('123.456.789-09');
Cpf::generate();
```

### Value objects

[](#value-objects)

```
use Cavalheri\LaravelBrazilDocuments\ValueObjects\CpfValue;

CpfValue::from('12345678909')->formatted();
CpfValue::from('123.456.789-09')->sanitized();
CpfValue::from('12345678909')->isValid();
```

### Validation rules

[](#validation-rules)

```
use Cavalheri\LaravelBrazilDocuments\Rules\Cpf;
use Cavalheri\LaravelBrazilDocuments\Rules\Cnpj;
use Cavalheri\LaravelBrazilDocuments\Rules\Cep;
use Cavalheri\LaravelBrazilDocuments\Rules\Cnh;
use Cavalheri\LaravelBrazilDocuments\Rules\Pis;
use Cavalheri\LaravelBrazilDocuments\Rules\Cns;
use Cavalheri\LaravelBrazilDocuments\Rules\TituloEleitor;

$request->validate([
    'cpf' => ['required', new Cpf],
    'cnpj' => ['required', new Cnpj],
    'cep' => ['required', new Cep],
    'cnh' => ['required', new Cnh],
    'pis' => ['required', new Pis],
    'cns' => ['required', new Cns],
    'titulo_eleitor' => ['required', new TituloEleitor],
]);
```

### Helpers

[](#helpers)

When enabled in config:

```
cpf('12345678909')->format();
cnpj('11222333000181')->format();
cep('01001000')->format();
cnh('12345678900')->format();
pis('12056413177')->format();
cns('279802393660003')->format();
tituloEleitor('825169091279')->format();
```

Localization
------------

[](#localization)

Validation messages are available in **English** (default) and **Portuguese (pt\_BR)**.

Publish translations:

```
php artisan vendor:publish --tag=brazil-documents-lang
```

Switch locale at runtime:

```
app()->setLocale('pt_BR');
```

Or override via config:

```
'locale' => 'pt_BR',
```

Validation behavior
-------------------

[](#validation-behavior)

- **CPF** and **CNPJ** use official check-digit algorithms.
- **Repeated sequences** (e.g. `11111111111`, `00000000000`) are rejected.
- **CEP** must contain exactly 8 numeric digits.

Testing
-------

[](#testing)

```
composer test
```

With coverage:

```
composer test:coverage
```

Project structure
-----------------

[](#project-structure)

```
config/brazil-documents.php
resources/lang/en/validation.php
resources/lang/pt_BR/validation.php
src/
├── Concerns/
├── Contracts/
├── Exceptions/
├── Facades/
├── Helpers/
├── Rules/
├── Services/
│   └── Documents/
├── Support/
├── ValueObjects/
└── LaravelBrazilDocumentsServiceProvider.php
tests/
├── Feature/
└── Unit/
```

Roadmap
-------

[](#roadmap)

Planned document types for future releases:

- State registration (Inscrição Estadual)
- PIX keys
- Boleto validation

Contributing
------------

[](#contributing)

Contributions are welcome. Please open an issue before large changes, and ensure tests pass:

```
composer test
```

Follow PSR-12 and keep the public API consistent with existing document handlers.

For AI-assisted development, see [AGENTS.md](AGENTS.md) and [CLAUDE.md](CLAUDE.md). Cursor rules live in `.cursor/rules/`.

See [SECURITY.md](SECURITY.md) to report vulnerabilities privately.

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE) for details.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance96

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

17d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dc9512de33226eedbf2597a3136c41dad3f0ddac10bb6b10d0a917f0876b257f?d=identicon)[LucasCavalheri](/maintainers/LucasCavalheri)

---

Top Contributors

[![LucasCavalheri](https://avatars.githubusercontent.com/u/104279631?v=4)](https://github.com/LucasCavalheri "LucasCavalheri (13 commits)")

---

Tags

brazildocumentslaravelphplaravelvalidationcepbrazildocumentscpfcnpj

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/cavalheri-laravel-brazil-documents/health.svg)

```
[![Health](https://phpackages.com/badges/cavalheri-laravel-brazil-documents/health.svg)](https://phpackages.com/packages/cavalheri-laravel-brazil-documents)
```

###  Alternatives

[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k38.3M138](/packages/propaganistas-laravel-phone)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M50](/packages/proengsoft-laravel-jsvalidation)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

76318.2M110](/packages/laravel-mcp)[illuminate/validation

The Illuminate Validation package.

18837.7M1.6k](/packages/illuminate-validation)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2462.3M6](/packages/laravel-validation-rules-credit-card)[propaganistas/laravel-disposable-email

Disposable email validator

6012.9M7](/packages/propaganistas-laravel-disposable-email)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
