PHPackages                             modulae/ptbr-doc-validator - 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. modulae/ptbr-doc-validator

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

modulae/ptbr-doc-validator
==========================

Brazilian document validators for Laravel.

0.1.2(4mo ago)01.1k↓17.8%[1 PRs](https://github.com/modulae/ptbr-doc-validator/pulls)MITPHPPHP ^8.3CI passing

Since Feb 19Pushed 1mo agoCompare

[ Source](https://github.com/modulae/ptbr-doc-validator)[ Packagist](https://packagist.org/packages/modulae/ptbr-doc-validator)[ Docs](https://github.com/modulae/ptbr-doc-validator)[ RSS](/packages/modulae-ptbr-doc-validator/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (22)Versions (7)Used By (0)

Brazilian document validators for Laravel.
==========================================

[](#brazilian-document-validators-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3f9ca03fa718b26afd47f8b6fd79d381bc4d872a41c9b746c2bc60136b4fe3f7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f64756c61652f707462722d646f632d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/modulae/ptbr-doc-validator)[![GitHub Tests Action Status](https://camo.githubusercontent.com/ae34ddd5091038e856b301e0917765af50bcdab6292fedec694503fc9246f3cd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f64756c61652f707462722d646f632d76616c696461746f722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/modulae/ptbr-doc-validator/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/00f1f467cb2a3f6f5594d4d9d494d8d55201a7757f6ba4baeb489c4beff9ef0d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f64756c61652f707462722d646f632d76616c696461746f722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/modulae/ptbr-doc-validator/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/a29312baa5de0a4b2a565afc463b09a25521739029417cd44aa54df82c1e64b2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f64756c61652f707462722d646f632d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/modulae/ptbr-doc-validator)

A lightweight Laravel package that provides validators and utilities for common Brazilian documents. The first supported document is CNPJ, including support for alphanumeric variants that are to be introduced in June 2026. It includes:

- A `cnpj` validation rule registered with Laravel's `Validator` facade.
- A `Cnpj` value object with helpers to normalize, format, cast in Eloquent models, and validate values.
- A `cnpjToString` helper to normalize strings and arrays of CNPJ values.
- Localized validation error messages (EN and PT-BR).

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

[](#installation)

Install via Composer:

```
composer require modulae/ptbr-doc-validator
```

Publish translations (optional, if you want to customize messages):

```
php artisan vendor:publish --tag="ptbr-doc-validator-translations"
```

Usage
-----

[](#usage)

### 1) Using the built-in `cnpj` validation rule

[](#1-using-the-built-in-cnpj-validation-rule)

```
use Illuminate\Support\Facades\Validator;

$validator = Validator::make(
    ['cnpj' => 'T6.JSP.XPS/0001-11'],
    ['cnpj' => 'cnpj']
);

$validator->passes(); // true/false
```

### 2) Using the `Cnpj` value object

[](#2-using-the-cnpj-value-object)

```
use Modulae\PTBRDocValidator\ValueObjects\Cnpj;

$cnpj = new Cnpj('T6.JSP.XPS/0001-11');
$cnpj->isValid();     // bool
$cnpj->raw();         // "T6JSPXPS000111"
$cnpj->formatted();   // "T6.JSP.XPS/0001-11"
(string) $cnpj;       // "T6JSPXPS000111"
```

Eloquent cast example:

```
class Company extends Model
{
    protected $casts = [
        'cnpj' => \Modulae\PTBRDocValidator\ValueObjects\Cnpj::class,
    ];
}
```

### 3) Using the `cnpjToString` helper

[](#3-using-the-cnpjtostring-helper)

```
use function Modulae\PTBRDocValidator\cnpjToString;

cnpjToString('T6.JSP.XPS/0001-11');
// => "T6JSPXPS000111"

cnpjToString(['32.332.643/0001-29', 'T6.JSP.XPS/0001-11']);
// => ['32332643000129', 'T6JSPXPS000111']
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance84

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60% 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 ~28 days

Total

3

Last Release

124d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1358552?v=4)[João Prado](/maintainers/joaoprado)[@joaoprado](https://github.com/joaoprado)

---

Top Contributors

[![joaoprado](https://avatars.githubusercontent.com/u/1358552?v=4)](https://github.com/joaoprado "joaoprado (6 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravelModulaeptbr-doc-validator

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/modulae-ptbr-doc-validator/health.svg)

```
[![Health](https://phpackages.com/badges/modulae-ptbr-doc-validator/health.svg)](https://phpackages.com/packages/modulae-ptbr-doc-validator)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

13.0k107.5M1.6k](/packages/spatie-laravel-permission)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.2k12.6M140](/packages/dedoc-scramble)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k5.4M50](/packages/spatie-laravel-pdf)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3915.5k](/packages/rawilk-profile-filament-plugin)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

46273.9k](/packages/harris21-laravel-fuse)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

25060.1k](/packages/vormkracht10-laravel-mails)

PHPackages © 2026

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