PHPackages                             leandrocfe/filament-ptbr-form-fields - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. leandrocfe/filament-ptbr-form-fields

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

leandrocfe/filament-ptbr-form-fields
====================================

Brazilian pt-BR form fields.

5.0.0(3mo ago)14398.7k—9.3%33[2 PRs](https://github.com/leandrocfe/filament-ptbr-form-fields/pulls)MITPHPPHP ^8.1 || ^8.2 || ^8.3CI passing

Since Apr 25Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/leandrocfe/filament-ptbr-form-fields)[ Packagist](https://packagist.org/packages/leandrocfe/filament-ptbr-form-fields)[ Docs](https://github.com/leandrocfe/filament-ptbr-form-fields)[ RSS](/packages/leandrocfe-filament-ptbr-form-fields/feed)WikiDiscussions 5.x Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (24)Used By (0)

Brazilian pt-BR form fields.
============================

[](#brazilian-pt-br-form-fields)

This 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).

This package uses [LaravelLegends/pt-br-validator](https://github.com/LaravelLegends/pt-br-validator) to validate Brazilian Portuguese fields.

[![image demo](https://raw.githubusercontent.com/leandrocfe/filament-ptbr-form-fields/develop/screenshots/v3x-example.png)](https://raw.githubusercontent.com/leandrocfe/filament-ptbr-form-fields/develop/screenshots/v3x-example.png)

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

[](#installation)

You can install the package via Composer:

```
composer require leandrocfe/filament-ptbr-form-fields:"^5.0"
```

### 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)

[](#filament-v2---if-you-are-using-filament-v2x-you-can-use-this-section)

### Filament V3 - if you are using Filament v3.x, you can use [this section](https://github.com/leandrocfe/filament-ptbr-form-fields/tree/3.x)

[](#filament-v3---if-you-are-using-filament-v3x-you-can-use-this-section)

### Filament V4 - if you are using Filament v4.x, you can use [this section](https://github.com/leandrocfe/filament-ptbr-form-fields/tree/4.x)

[](#filament-v4---if-you-are-using-filament-v4x-you-can-use-this-section)

Usage
-----

[](#usage)

### CPF / CNPJ

[](#cpf--cnpj)

To create a dynamic input that accepts either CPF or CNPJ, use:

```
use Leandrocfe\FilamentPtbrFormFields\Document;
//CPF or CNPJ
Document::make('cpf_or_cnpj')
    ->dynamic()
```

If you want to create an input that only accepts CPF or only accepts CNPJ, use:

```
//CPF
Document::make('cpf')
    ->cpf()
```

```
//CNPJ
Document::make('cnpj')
    ->cnpj()
```

If you want to use a custom mask for the input, use the cpf() or cnpj() method with a string argument representing the desired mask:

```
Document::make('cpf')
    ->cpf('999999999-99')
```

```
Document::make('cnpj')
    ->cnpj('99999999/9999-99')
```

### Validation

[](#validation)

`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`

You can disable validation using the `validation(false)` method:

```
Document::make('cpf_or_cnpj')
    ->validation(false)
    ->dynamic()
```

```
Document::make('cpf')
    ->validation(false)
    ->cpf()
```

### Phone number

[](#phone-number)

To create a dynamic input that formats phone numbers with DDD, use:

```
use Leandrocfe\FilamentPtbrFormFields\PhoneNumber;
PhoneNumber::make('phone_number')
```

If you want to use a custom phone number format, use the `mask() method with a string argument representing the desired format:

```
PhoneNumber::make('phone_number')
    ->mask('(99) 99999-9999')
```

```
PhoneNumber::make('phone_number')
    ->mask('+99 (99) 99999-9999')
```

### Money

[](#money)

To create a money input field, use the following syntax:

```
use Leandrocfe\FilamentPtbrFormFields\Money;
Money::make('price')
    ->default('100,00')

#output: 100.00
```

This is suitable for use with `decimal` or `float` data types.

#### Using Integer Values

[](#using-integer-values)

If you prefer to work with integer values, you can format the money input using the `intFormat()` method:

```
use Leandrocfe\FilamentPtbrFormFields\Money;
Money::make('price')
    ->default(10000)
    ->intFormat()

#output: 10000
```

#### Getting the Raw State

[](#getting-the-raw-state)

To retrieve the raw state of the field, you can use the `dehydratedMask() method:

```
use Leandrocfe\FilamentPtbrFormFields\Money;
Money::make('price')
    ->default('100,00')
    ->dehydrateMask()

#output: 100,00
```

If you need to remove the prefix from the money input, simply pass null to the `prefix()` method:

```
Money::make('price')
    ->prefix(null)
```

#### Currency Formatting

[](#currency-formatting)

This package leverages the `archtechx/money` package under the hood. By default, it uses the `BRL` (Brazilian Real) format for currency values.

If you want to switch to the `USD` (United States Dollar) format, you can do so with the following code:

```
use Leandrocfe\FilamentPtbrFormFields\Currencies\USD;

Money::make('price')
    ->currency(USD::class)
    ->prefix('$')
```

You can also define custom currencies to suit your specific needs:

```
/*
 * app/Currencies/EUR.php
 */

declare(strict_types=1);

namespace App\Currencies;

use ArchTech\Money\Currency;

class EUR extends Currency
{
    /*
     * Code of the currency.
     */
    public string $code = 'EUR';

    /*
     * Name of the currency.
     */
    public string $name = 'Euro';

    /*
     * Rate of this currency relative to the default currency.
     */
    public float $rate = 1.0;

    /*
     * Number of decimals used in money calculations.
     */
    public int $mathDecimals = 2;

    /*
     * Number of decimals used in the formatted value
     */
    public int $displayDecimals = 2;

    /*
     * How many decimals of the currency's values should get rounded
     */
    public int $rounding = 2;

    /*
     * Prefix placed at the beginning of the formatted value.
    */
    public string $prefix = '€';

    /*
     * The language code.
     */
    public string $locale = 'pt';

    /*
     * The character used to separate the decimal values.
     */
    public string $decimalSeparator = '.';

    /*
     * The character used to separate groups of thousands
     */
    public string $thousandsSeparator = ',';
}
```

```
use App\Currencies\EUR;

Money::make('price')
->currency(EUR::class)
->prefix('€')
```

### CEP (Brazilian ZIP Code)

[](#cep-brazilian-zip-code)

The CEP field provides automatic address lookup through configurable providers like ViaCep and BrasilAPI.

#### Basic Usage

[](#basic-usage)

```
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Utilities\Set;
use Leandrocfe\FilamentPtbrFormFields\Cep;
use Leandrocfe\FilamentPtbrFormFields\CepFieldMode;
use Leandrocfe\FilamentPtbrFormFields\Providers\ViaCepProvider;

Cep::make('postal_code')
    ->mode(CepFieldMode::SUFFIX) // or CepFieldMode::ON_BLUR
    ->api(ViaCepProvider::class, function (Set $set, ?array $response) {
        $set('street', data_get($response, 'logradouro'));
        $set('neighborhood', data_get($response, 'bairro'));
        $set('city', data_get($response, 'localidade'));
        $set('state', data_get($response, 'uf'));
    }),

TextInput::make('street'),
TextInput::make('neighborhood'),
TextInput::make('city'),
TextInput::make('state'),
```

#### Lookup Modes

[](#lookup-modes)

**ON\_BLUR (default)**: Automatically fetches address when the field loses focus

```
Cep::make('postal_code')
    ->mode(CepFieldMode::ON_BLUR)
    ->api(ViaCepProvider::class, function (Set $set, ?array $response) {
        // ...
    })
```

**SUFFIX**: Shows a search button next to the field

```
Cep::make('postal_code')
    ->mode(CepFieldMode::SUFFIX)
    ->api(ViaCepProvider::class, function (Set $set, ?array $response) {
        // ...
    })
```

#### Custom Error Message

[](#custom-error-message)

```
Cep::make('postal_code')
    ->errorMessage('Invalid CEP')
    ->api(ViaCepProvider::class, function (Set $set, ?array $response) {
        // ...
    })
```

#### Available Providers

[](#available-providers)

- **ViaCepProvider**: Default provider using [ViaCep API](https://viacep.com.br/)
- **BrasilApiProvider**: Alternative provider using [BrasilAPI](https://brasilapi.com.br/)

```
use Leandrocfe\FilamentPtbrFormFields\Providers\BrasilApiProvider;

Cep::make('cep')
    ->api(BrasilApiProvider::class, function (Set $set, ?array $response) {
        // ...
    })
```

#### Custom Provider

[](#custom-provider)

You can create your own provider by implementing `CepProviderInterface`:

```
use Leandrocfe\FilamentPtbrFormFields\Providers\CepProviderInterface;
use Illuminate\Support\Collection;

class MyCustomProvider implements CepProviderInterface
{
    public function fetch(string $cep): null|Collection|array
    {
        // Your implementation
        return $response;
    }
}
```

#### Legacy Method (Deprecated)

[](#legacy-method-deprecated)

The old `viaCep()` method is still available for backward compatibility but will be removed:

```
Cep::make('postal_code')
    ->mode(CepFieldMode::SUFFIX)
    ->viaCep(
        mode: 'suffix',
        errorMessage: 'CEP inválido.',
        setFields: [
            'street' => 'logradouro',
            'district' => 'bairro',
            'city' => 'localidade',
            'state' => 'uf'
        ]
    )
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability within this package, please send an e-mail to .

Credits
-------

[](#credits)

- [Leandro Costa Ferreira](https://github.com/leandrocfe)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

60

—

FairBetter than 99% of packages

Maintenance85

Actively maintained with recent releases

Popularity50

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 64.2% 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 ~56 days

Recently: every ~31 days

Total

19

Last Release

98d ago

Major Versions

0.1.0 → 3.0.02023-08-15

2.0.0 → 3.0.12023-08-30

3.x-dev → 4.0.02025-10-14

4.x-dev → 5.0.02026-02-10

PHP version history (4 changes)0.1.0PHP ^8.1

3.0.5PHP ^8.1 || ^8.2

3.1.0PHP ^8.1 || ^8.2 || ^8.3

5.x-devPHP ^8.2 || ^8.3

### Community

Maintainers

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

---

Top Contributors

[![leandrocfe](https://avatars.githubusercontent.com/u/3833889?v=4)](https://github.com/leandrocfe "leandrocfe (77 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (16 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")[![rmsramos](https://avatars.githubusercontent.com/u/5170473?v=4)](https://github.com/rmsramos "rmsramos (8 commits)")[![leandrogehlen](https://avatars.githubusercontent.com/u/1750751?v=4)](https://github.com/leandrogehlen "leandrogehlen (3 commits)")[![patriciomartinns](https://avatars.githubusercontent.com/u/20000058?v=4)](https://github.com/patriciomartinns "patriciomartinns (3 commits)")[![gustavosantossh](https://avatars.githubusercontent.com/u/82613893?v=4)](https://github.com/gustavosantossh "gustavosantossh (2 commits)")[![danielcei](https://avatars.githubusercontent.com/u/19355609?v=4)](https://github.com/danielcei "danielcei (2 commits)")[![asi9solucoesdigitais](https://avatars.githubusercontent.com/u/240100643?v=4)](https://github.com/asi9solucoesdigitais "asi9solucoesdigitais (1 commits)")

---

Tags

filamentphplaravelphplaravelleandrocfefilament-ptbr-form-fields

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/leandrocfe-filament-ptbr-form-fields/health.svg)

```
[![Health](https://phpackages.com/badges/leandrocfe-filament-ptbr-form-fields/health.svg)](https://phpackages.com/packages/leandrocfe-filament-ptbr-form-fields)
```

###  Alternatives

[leandrocfe/filament-apex-charts

Apex Charts integration for Filament PHP.

4861.2M8](/packages/leandrocfe-filament-apex-charts)[guava/calendar

Adds support for vkurko/calendar to Filament PHP.

298241.0k3](/packages/guava-calendar)[pboivin/filament-peek

Full-screen page preview modal for Filament

253319.6k12](/packages/pboivin-filament-peek)[dotswan/filament-map-picker

Easily pick and retrieve geo-coordinates using a map-based interface in your Filament applications.

124139.3k2](/packages/dotswan-filament-map-picker)[creagia/filament-code-field

A Filamentphp input field to edit or view code data.

58289.3k3](/packages/creagia-filament-code-field)[swisnl/filament-backgrounds

Beautiful backgrounds for Filament auth pages

54149.2k6](/packages/swisnl-filament-backgrounds)

PHPackages © 2026

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