Require this package in your composer.json and update composer. This will download the package and the dependencies libraries also.
composer require lsnepomuceno/laravel-brazilian-ceps
Export the settings file using the command below
php artisan vendor:publish --tag=brazilian-ceps
<?php
use LSNepomuceno\LaravelBrazilianCeps\Services\CepService;
class ExampleController() {
// PHP 8: Constructor property promotion
public function __construct(protected CepService $cepService) { }
public function dummyFunction(string|int $cep){
$address = $this->cepService->get($cep);
dd($address);
}
}
LSNepomuceno\LaravelBrazilianCeps\Entities\CepEntity {
city: string,
cep: string,
street: string,
state: string,
uf: string,
neighborhood: string,
number: string | int | null,
complement: string | null,
}
// config/brazilian-ceps.php
<?php
'throw_not_found_exception' => true
<?php
use LSNepomuceno\LaravelBrazilianCeps\Services\CepService;
use LSNepomuceno\LaravelBrazilianCeps\Exceptions\CepNotFoundException;
class ExampleController() {
// PHP 8: Constructor property promotion
public function __construct(protected CepService $cepService) { }
public function dummyFunction(string|int $cep){
try {
$address = $this->cepService->get($cep);
dd($address);
} catch(CepNotFoundException $e) {
// TODO necessary
}
}
}
Verb | URI | Invokable Controller | Route Name |
---|---|---|---|
GET | api/consult-cep/{cep} | LSNepomuceno\LaravelBrazilianCeps\Controllers\ConsultCepController | consult-cep.api |
// config/brazilian-ceps.php
<?php
'enable_api_consult_cep_route' => false
// config/brazilian-ceps.php
<?php
'not_found_message' => 'Type here the message you want.'
// config/brazilian-ceps.php
<?php
'api_route_middleware' => ['guest']
// config/brazilian-ceps.php
<?php
'cache_results' => true,
'cache_lifetime_in_days' => 30
The MIT License (MIT). Please see License File for more information.