Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Cpf Cnpj Laravel Package

phillarmonic/cpf-cnpj

phillarmonic/cpf-cnpj provides Laravel-friendly helpers for validating and formatting Brazilian CPF and CNPJ documents, making document checks easier to use in forms, requests, and models.

Deep Wiki
Context7

phillarmonic/cpf-cnpj is a lightweight PHP/Laravel package for working with Brazilian CPF and CNPJ documents. It helps validate tax IDs, apply standard formatting masks, and generate valid values, making it useful for forms, seeders, and domain rules.

  • Validate CPF and CNPJ numbers
  • Format and strip document masks
  • Generate valid CPF/CNPJ values for tests
  • Integrate with Laravel validation rules
  • Simple, framework-friendly API
Frequently asked questions about Cpf Cnpj
How do I install phillarmonic/cpf-cnpj in a Laravel application?
Install the package with Composer using the package name phillarmonic/cpf-cnpj. Laravel typically auto-discovers package service providers, but if your application does not, register the provider manually. After installation, you can reference the package's CPF and CNPJ validation rules in your FormRequests, controllers, or inline validators.
Which Laravel and PHP versions are supported by this package?
Compatibility depends on the PHP and Laravel constraints declared in the package's composer.json. Check those constraints before installing or upgrading Laravel, because validation APIs and PHP requirements can change between major versions. If your application uses a modern Laravel release with Composer auto-discovery, confirm the constraints allow it and run your validation tests after upgrading.
How do I use the CPF or CNPJ rule inside a Laravel FormRequest?
Add the package's CPF or CNPJ rule to the rules array for the relevant field in your FormRequest. Use the CPF rule for individual tax IDs and the CNPJ rule for company tax IDs. Then validate the request as usual; Laravel will return a validation error when the document format or check digits are invalid.
Does the package accept formatted CPF and CNPJ values with dots, slashes, and dashes?
The rules are designed to check format and verify check digits, but whether punctuation is accepted depends on the rule implementation. Test both masked and unmasked values in your application to confirm the expected behavior. If you need a single canonical format, normalize the input by stripping non-digits before validation or add a preparation step in your FormRequest.
What is the difference between validating CPF and CNPJ?
CPF is an individual Brazilian tax ID with 11 digits, while CNPJ is a company tax ID with 14 digits. They use different check-digit algorithms and formats, so you should use the matching rule for each field. Keeping separate rules prevents a valid CPF from being accepted in a CNPJ field or vice versa.
Can I customize the validation error messages for CPF and CNPJ fields?
Yes, Laravel lets you override messages through the messages method in a FormRequest or by passing custom messages to the validator. You can also use attribute names to make errors read naturally, such as CPF or CNPJ instead of the database field name. Check whether the package ships default messages, then override them only where your application needs different wording.
How should I test CPF and CNPJ validation in my Laravel test suite?
Write feature or unit tests that submit known valid and invalid CPF and CNPJ values and assert the expected validation results. Cover both formatted and digits-only inputs if your application accepts both. Avoid using real personal tax IDs in tests; use mathematically valid test values or fixtures instead.
Is this package suitable for production APIs that accept tax IDs?
Yes, a dedicated CPF and CNPJ validation rule helps reject malformed documents before they reach your business logic. Remember that check-digit validation does not prove the document exists or belongs to the person or company submitting it. Combine validation with authentication, rate limiting, input normalization, and appropriate data protection practices.
How does phillarmonic/cpf-cnpj compare with other Laravel CPF and CNPJ packages?
This package focuses narrowly on validating CPF and CNPJ documents in Laravel, which is useful if you only need reliable validation rules. Other packages may also provide masking, document generation, Eloquent casts, or model traits. Choose based on whether you want a lightweight validator or a broader toolkit.
Is the package maintained, and how should I handle Laravel upgrades?
Check the package's Packagist and repository activity, release history, and Composer constraints to judge maintenance status. Pin a known-good version in composer.json and run your validation tests whenever you upgrade Laravel or PHP. If the package becomes inactive, you can fork it or copy the validation logic into your own application.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core