Install the laravellegends/pt-br-validator package:
composer require laravellegends/pt-br-validator
use Filament\Support\RawJs; TextInput::make('cpf_cnpj') ->mask(RawJs::make(<<<'JS' $input.length > 14 ? '99.999.999/9999-99' : '999.999.999-99' JS)) ->rule('cpf_ou_cnpj')
TextInput::make('cpf') ->mask('999.999.999-99') ->rule('cpf')
TextInput::make('cnpj') ->mask('99.999.999/9999-99') ->rule('cnpj')
Go to AppServiceProvider at app\Providers\AppServiceProvider.php and add the following:
use Filament\Facades\Filament; /** * Bootstrap any application services. * * @return void */public function boot(){ Filament::registerScripts([ ], true);}
TextInput::make('cpf_cnpj') ->extraAlpineAttributes(['x-mask:dynamic' => '$input.length >14 ? \'99.999.999/9999-99\' : \'999.999.999-99\'']) ->rule('cpf_ou_cnpj')
TextInput::make('cpf') ->extraAlpineAttributes(['x-mask' => '999.999.999-99']) ->rule('cpf')
TextInput::make('cnpj') ->extraAlpineAttributes(['x-mask' => '99.999.999/9999-99']) ->rule('cnpj')
Core team member at Filament. Founded the Filament Brazilian Community. Learn more at leandroferreira.dev.br.