{"id":16462218,"url":"https://github.com/leandrocfe/filament-ptbr-form-fields","last_synced_at":"2026-02-10T09:18:51.626Z","repository":{"id":155510113,"uuid":"622975688","full_name":"leandrocfe/filament-ptbr-form-fields","owner":"leandrocfe","description":"This package provides custom form fields for Filament (\u003e=v2.17.28) that are commonly used in Brazilian web applications, such as CPF/CNPJ validation, phone number formatting, money with currency symbol, and CEP integration with ViaCep.","archived":false,"fork":false,"pushed_at":"2025-03-12T12:14:19.000Z","size":869,"stargazers_count":116,"open_issues_count":16,"forks_count":22,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-12T04:02:14.084Z","etag":null,"topics":["filamentphp","laravel","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leandrocfe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-03T12:53:21.000Z","updated_at":"2025-05-12T03:21:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"50247c85-e6cc-4160-b704-e03a0aa25c34","html_url":"https://github.com/leandrocfe/filament-ptbr-form-fields","commit_stats":{"total_commits":41,"total_committers":6,"mean_commits":6.833333333333333,"dds":0.5853658536585367,"last_synced_commit":"5a101d0987b36ee0fec594d4c9c62ead9bc2c527"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandrocfe%2Ffilament-ptbr-form-fields","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandrocfe%2Ffilament-ptbr-form-fields/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandrocfe%2Ffilament-ptbr-form-fields/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandrocfe%2Ffilament-ptbr-form-fields/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leandrocfe","download_url":"https://codeload.github.com/leandrocfe/filament-ptbr-form-fields/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254485053,"owners_count":22078767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filamentphp","laravel","php"],"created_at":"2024-10-11T11:10:44.231Z","updated_at":"2026-02-10T09:18:51.588Z","avatar_url":"https://github.com/leandrocfe.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Brazilian pt-BR form fields.\n\nThis package provides custom form fields for [Filament](https://filamentphp.com/) that are commonly used in Brazilian web applications, such as CPF/CNPJ validation, phone number formatting, money with currency symbol, and CEP integration with [ViaCep](https://viacep.com.br).\n\nThis package uses [LaravelLegends/pt-br-validator](https://github.com/LaravelLegends/pt-br-validator) to validate Brazilian Portuguese fields.\n\n![image demo](https://raw.githubusercontent.com/leandrocfe/filament-ptbr-form-fields/develop/screenshots/v3x-example.png)\n\n## Installation\n\nYou can install the package via Composer:\n\n```bash\ncomposer require leandrocfe/filament-ptbr-form-fields:\"^3.0\"\n```\n\n### Filament V2 - if you are using Filament v2.x, you can use [this section](https://github.com/leandrocfe/filament-ptbr-form-fields/tree/2.0.0)\n\n## Usage\n\n### CPF / CNPJ\n\nTo create a dynamic input that accepts either CPF or CNPJ, use:\n\n```php\nuse Leandrocfe\\FilamentPtbrFormFields\\Document;\n//CPF or CNPJ\nDocument::make('cpf_or_cnpj')\n    -\u003edynamic()\n```\n\nIf you want to create an input that only accepts CPF or only accepts CNPJ, use:\n\n```php\n//CPF\nDocument::make('cpf')\n    -\u003ecpf()\n```\n\n```php\n//CNPJ\nDocument::make('cnpj')\n    -\u003ecnpj()\n```\n\nIf you want to use a custom mask for the input, use the cpf() or cnpj() method with a string argument representing the desired mask:\n\n```php\nDocument::make('cpf')\n    -\u003ecpf('999999999-99')\n```\n\n```php\nDocument::make('cnpj')\n    -\u003ecnpj('99999999/9999-99')\n```\n\n### Validation\n`Document` uses [LaravelLegends/pt-br-validator](https://github.com/LaravelLegends/pt-br-validator) to validate Brazilian Portuguese fields by default - `cpf_ou_cnpj` | `cpf` | `cnpj`\n\nYou can disable validation using the `validation(false)` method:\n\n```php\nDocument::make('cpf_or_cnpj')\n    -\u003evalidation(false)\n    -\u003edynamic()\n```\n\n```php\nDocument::make('cpf')\n    -\u003evalidation(false)\n    -\u003ecpf()\n```\n\n### Phone number\n\nTo create a dynamic input that formats phone numbers with DDD, use:\n\n```php\nuse Leandrocfe\\FilamentPtbrFormFields\\PhoneNumber;\nPhoneNumber::make('phone_number')\n```\n\nIf you want to use a custom phone number format, use the `mask() method with a string argument representing the desired format:\n\n```php\nPhoneNumber::make('phone_number')\n    -\u003emask('(99) 99999-9999')\n```\n\n```php\nPhoneNumber::make('phone_number')\n    -\u003emask('+99 (99) 99999-9999')\n```\n\n### Money\n\nTo create a money input field, use the following syntax:\n\n```php\nuse Leandrocfe\\FilamentPtbrFormFields\\Money;\nMoney::make('price')\n    -\u003edefault('100,00')\n\n#output: 100.00\n```\n\nThis is suitable for use with `decimal` or `float` data types.\n\n#### Using Integer Values\n\nIf you prefer to work with integer values, you can format the money input using the `intFormat()` method:\n\n```php\nuse Leandrocfe\\FilamentPtbrFormFields\\Money;\nMoney::make('price')\n    -\u003edefault(10000)\n    -\u003eintFormat()\n\n#output: 10000\n```\n#### Getting the Raw State\n\nTo retrieve the raw state of the field, you can use the `dehydratedMask() method:\n\n```php\nuse Leandrocfe\\FilamentPtbrFormFields\\Money;\nMoney::make('price')\n    -\u003edefault('100,00')\n    -\u003edehydrateMask()\n\n#output: 100,00\n```\n\nIf you need to remove the prefix from the money input, simply pass null to the `prefix()` method:\n```php\nMoney::make('price')\n    -\u003eprefix(null)\n```\n#### Currency Formatting\n\nThis package leverages the `archtechx/money` package under the hood. By default, it uses the `BRL` (Brazilian Real) format for currency values.\n\nIf you want to switch to the `USD` (United States Dollar) format, you can do so with the following code:\n```php\nuse Leandrocfe\\FilamentPtbrFormFields\\Currencies\\USD;\n\nMoney::make('price')\n    -\u003ecurrency(USD::class)\n    -\u003eprefix('$')\n```\n\nYou can also define custom currencies to suit your specific needs:\n\n\n```php\n\n/*\n * app/Currencies/EUR.php\n */\n \ndeclare(strict_types=1);\n\nnamespace App\\Currencies;\n\nuse ArchTech\\Money\\Currency;\n\nclass EUR extends Currency\n{\n    /*\n     * Code of the currency.\n     */\n    public string $code = 'EUR';\n\n    /*\n     * Name of the currency.\n     */\n    public string $name = 'Euro';\n\n    /*\n     * Rate of this currency relative to the default currency.\n     */\n    public float $rate = 1.0;\n\n    /*\n     * Number of decimals used in money calculations.\n     */\n    public int $mathDecimals = 2;\n\n    /*\n     * Number of decimals used in the formatted value\n     */\n    public int $displayDecimals = 2;\n\n    /*\n     * How many decimals of the currency's values should get rounded\n     */\n    public int $rounding = 2;\n\n    /*\n     * Prefix placed at the beginning of the formatted value.\n    */\n    public string $prefix = '€';\n\n    /*\n     * The language code.\n     */\n    public string $locale = 'pt';\n\n    /*\n     * The character used to separate the decimal values.\n     */\n    public string $decimalSeparator = '.';\n\n    /*\n     * The character used to separate groups of thousands\n     */\n    public string $thousandsSeparator = ',';\n}\n\n```\n\n```php\nuse App\\Currencies\\EUR;\n\nMoney::make('price')\n-\u003ecurrency(EUR::class)\n-\u003eprefix('€')\n```\n\n### Address\n\nTo integrate with the ViaCep API for CEP validation and address autofill, use:\n\n```php\nuse Leandrocfe\\FilamentPtbrFormFields\\Cep;\nuse Filament\\Forms\\Components\\TextInput;\nCep::make('postal_code')\n    -\u003eviaCep(\n        mode: 'suffix', // Determines whether the action should be appended to (suffix) or prepended to (prefix) the cep field, or not included at all (none).\n        errorMessage: 'CEP inválido.', // Error message to display if the CEP is invalid.\n\n        /**\n         * Other form fields that can be filled by ViaCep.\n         * The key is the name of the Filament input, and the value is the ViaCep attribute that corresponds to it.\n         * More information: https://viacep.com.br/\n         */\n        setFields: [\n            'street' =\u003e 'logradouro',\n            'number' =\u003e 'numero',\n            'complement' =\u003e 'complemento',\n            'district' =\u003e 'bairro',\n            'city' =\u003e 'localidade',\n            'state' =\u003e 'uf'\n        ]\n    ),\n\nTextInput::make('street'),\nTextInput::make('number'),\nTextInput::make('complement'),\nTextInput::make('district'),\nTextInput::make('city'),\nTextInput::make('state'),\n```\n\nThe mode parameter specifies whether the search action should be appended to or prepended to the CEP field, using the values suffix or prefix. Alternatively, you can use the none value with the `-\u003elive(onBlur: true)` method to indicate that the other address fields will be automatically filled only when the CEP field loses focus.\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nIf you discover a security vulnerability within this package, please send an e-mail to \u003cleandrocfe@gmail.com\u003e.\n\n## Credits\n\n-   [Leandro Costa Ferreira](https://github.com/leandrocfe)\n-   [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleandrocfe%2Ffilament-ptbr-form-fields","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleandrocfe%2Ffilament-ptbr-form-fields","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleandrocfe%2Ffilament-ptbr-form-fields/lists"}