- How do I add a CEP field to a Filament form?
- Use the `CepInput::make()` method in your Filament form definition. For example: `CepInput::make('cep')->required()`. The field will automatically format the input as `99999-999` and validate the CEP format. You can also customize labels, error messages, and API provider settings.
- Which CEP APIs does this package support?
- The package supports multiple APIs out of the box: BrasilAPI, ViaCEP, and AwesomeAPI. You can configure the default API in the field settings or override it globally via the package configuration. Each API has different rate limits, so test which works best for your use case.
- Does this package work with Laravel 10 and Filament 5.x?
- Yes, this package is fully compatible with Laravel 10.x and Filament 5.3+. It leverages Filament’s form system and follows its conventions, ensuring smooth integration. Always check the package’s `composer.json` for the latest supported versions to avoid compatibility issues.
- How does caching work for CEP lookups?
- The package uses Laravel’s model caching to store CEP responses, reducing API calls and improving performance. Cache invalidation is handled automatically via queues, ensuring stale data doesn’t persist. You can configure cache TTL (time-to-live) and monitor cache hit rates for optimization.
- Can I customize the address fields populated by the CEP lookup?
- Yes, you can map the API response fields to your model attributes using the `map()` method. For example: `CepInput::make('cep')->map('street', 'street')->map('city', 'city')`. This allows you to control which address fields are populated in your Filament form.
- What happens if the CEP API is down or returns an error?
- The package falls back to cached responses if available. You can also configure custom error messages or retry logic. For critical applications, consider implementing a local CEP database fallback or monitoring API uptime to avoid disruptions.
- How do I test this package in my CI/CD pipeline?
- Use Laravel’s HTTP testing helpers like `Http::fake()` to mock API responses in your tests. For example: `Http::fake(['https://cep.awesomeapi.com.br/*' => Http::response(['street' => 'Test Street'])]);`. This ensures your tests run without external dependencies.
- Is there a way to disable automatic address lookup?
- Yes, you can disable the address lookup feature entirely by setting `enableLookup(false)` on the `CepInput` field. This is useful if you only need CEP validation without fetching additional address data. You can also disable it globally via package configuration.
- Does this package support Brazilian state abbreviations?
- Yes, the package includes full support for Brazilian state abbreviations (e.g., SP, RJ, MG). When a valid CEP is entered, the corresponding state will be automatically populated in the address fields. You can customize the state field mapping if needed.
- What are the alternatives to this package for CEP handling in Laravel?
- Alternatives include manually integrating with ViaCEP’s API using Laravel’s HTTP client or using packages like `spatie/laravel-cep`. However, those require more setup for form integration, validation, and caching. This package streamlines the process by providing a ready-to-use Filament component with built-in features like auto-formatting and caching.