PHP code example of lsnepomuceno / laravel-brazilian-ceps

1. Go to this page and download the library: Download lsnepomuceno/laravel-brazilian-ceps library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lsnepomuceno / laravel-brazilian-ceps example snippets




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


  
  'throw_not_found_exception' => true
  



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
       }
    }
}


// config/brazilian-ceps.php


  
  'enable_api_consult_cep_route' => false
  

// config/brazilian-ceps.php


  
  'not_found_message' => 'Type here the message you want.'
  

// config/brazilian-ceps.php


  
  'api_route_middleware' => ['guest']
  

// config/brazilian-ceps.php


  
  'cache_results' => true,
  
  'cache_lifetime_in_days' => 30
  
Shell
php artisan vendor:publish --tag=brazilian-ceps