modulae/ptbr-doc-validator
Composer 安装命令:
composer require modulae/ptbr-doc-validator
包简介
Brazilian document validators for Laravel.
README 文档
README
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
cnpjvalidation rule registered with Laravel'sValidatorfacade. - A
Cnpjvalue object with helpers to normalize, format, cast in Eloquent models, and validate values. - A
cnpjToStringhelper to normalize strings and arrays of CNPJ values. - Localized validation error messages (EN and PT-BR).
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
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
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
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
composer test
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 703
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-19