The Filament CEP Field is a custom input component designed specifically for Brazilian postal codes (CEP - Código de Endereçamento Postal). This component extends Filament's form capabilities by providing a specialized input field that handles CEP formatting, validation, and automatic address lookup.
This component is perfect for Brazilian applications that need to collect address information efficiently and accurately.
You can install the package via composer:
composer require jeffersongoncalves/filament-cep-field
Publish and run the migration file:
php artisan vendor:publish --tag=cep-migrationsphp artisan migrate
Once installed, you can use the CepInput component in your Filament forms. The component automatically applies a CEP mask (99999-999), validates the input, and can automatically populate address fields when a valid CEP is found.
use JeffersonGoncalves\Filament\CepField\Forms\Components\CepInput; // Basic usageCepInput::make('cep') ->required(), // Advanced usage with all available optionsCepInput::make('cep') ->required() ->setMode('suffix') // 'prefix' or 'suffix' (default: 'suffix') ->setActionLabel('Buscar CEP') // Custom search button label ->setActionLabelHidden(false) // Show/hide action label (default: false) ->setErrorMessage('CEP não encontrado.') // Custom error message ->setStreetField('street') // Field to populate with street name ->setNeighborhoodField('neighborhood') // Field to populate with neighborhood ->setCityField('city') // Field to populate with city name ->setStateField('state'), // Field to populate with state
setMode(string $mode)
Sets the position of the search action button.
'suffix'
(default): Places the button after the input field'prefix'
: Places the button before the input fieldsetActionLabel(string $label)
Customizes the label text for the search action button.
'Buscar CEP'
setActionLabelHidden(bool $hidden)
Controls whether the action button label is visible.
true
: Shows only the magnifying glass iconfalse
(default): Shows both icon and labelsetErrorMessage(string $message)
Sets a custom error message when CEP lookup fails.
'CEP inválido.'
These methods allow you to specify which form fields should be automatically populated with the address information:
setStreetField(string $fieldName)
- Default: 'street'
setNeighborhoodField(string $fieldName)
- Default: 'neighborhood'
setCityField(string $fieldName)
- Default: 'city'
setStateField(string $fieldName)
- Default: 'state'
CepInput::make('postal_code') ->label('CEP') ->required()
CepInput::make('cep') ->label('CEP') ->required() ->setStreetField('endereco') ->setNeighborhoodField('bairro') ->setCityField('cidade') ->setStateField('estado')
CepInput::make('cep') ->label('Código Postal') ->setMode('prefix') ->setActionLabel('Consultar') ->setActionLabelHidden(false) ->setErrorMessage('CEP não encontrado ou inválido.')
This package makes HTTPS requests to external APIs (BrasilAPI, ViaCEP, and AwesomeAPI) to retrieve CEP information. If you encounter SSL certificate errors, you may need to configure PHP to use a proper CA certificate bundle.
The cacert.pem
file is a bundle of Certificate Authority (CA) certificates that PHP uses to verify SSL/TLS connections. Without proper CA certificates, PHP cannot verify the authenticity of HTTPS connections, leading to SSL errors.
You might encounter errors like:
cURL error 60: SSL certificate problem: unable to get local issuer certificate
SSL certificate verification failed
Download the latest CA certificate bundle from the official cURL website:
# Download the latest cacert.pem filecurl -o cacert.pem https://curl.se/ca/cacert.pem
Or download it manually from: https://curl.se/ca/cacert.pem
Place the cacert.pem
file in a secure location on your server, for example:
C:\php\extras\ssl\cacert.pem
/etc/ssl/certs/cacert.pem
or /usr/local/etc/ssl/cacert.pem
Edit your php.ini
file and add/update the following lines:
; Enable SSL certificate verificationopenssl.cafile = "C:\php\extras\ssl\cacert.pem" ; Windows path; openssl.cafile = "/etc/ssl/certs/cacert.pem" ; Linux/macOS path ; For cURL specificallycurl.cainfo = "C:\php\extras\ssl\cacert.pem" ; Windows path; curl.cainfo = "/etc/ssl/certs/cacert.pem" ; Linux/macOS path
After modifying php.ini
, restart your web server (Apache, Nginx, etc.) or PHP-FPM service.
To verify that SSL certificates are working correctly, you can test the configuration:
// Test SSL connection$response = file_get_contents('https://brasilapi.com.br/api/cep/v1/01310100');if ($response !== false) { echo "SSL configuration is working correctly!";} else { echo "SSL configuration needs attention.";}
If you cannot modify php.ini
, you can also:
Set environment variable (not recommended for production):
export SSL_CERT_FILE=/path/to/cacert.pem
Use Laravel HTTP client options in your application:
Http::withOptions([ 'verify' => '/path/to/cacert.pem'])->get('https://api.example.com');
Note: Disabling SSL verification ('verify' => false
) is strongly discouraged as it makes your application vulnerable to man-in-the-middle attacks.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.