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([ 'https://unpkg.com/@alpinejs/mask@3.x.x/dist/cdn.min.js', ], 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')
Leandro is a PHP/Laravel developer who has been coding for close to 7+ years. You can learn more about Leandro on his website.