artesaos/zipcode

This package is abandoned and no longer maintained. No replacement package was suggested.

ZipCode From Brazil

This package has no released version yet, and little information is available.


README

Web Service provided by http://viacep.com.br/

Canducci Cep

Demo

Demo Artesãos ZipCode

Quick start

Required setup

In the require key of composer.json file add the following

"artesaos/zipcode": "dev-master"

Run the Composer update comand

$ composer update

In your config/app.php add 'Artesaos\ZipCode\Providers\ZipCodeServiceProvider' to the end of the providers array:

'providers' => array(
    ...,
    'Illuminate\Workbench\WorkbenchServiceProvider',
    'Artesaos\ZipCode\Providers\ZipCodeServiceProvider',

),

At the end of config/app.php add 'ZipCode' => 'Artesaos\ZipCode\Facade\ZipCode' to the aliases array:

'aliases' => array(
    ...,
    'View'       => 'Illuminate\Support\Facades\View',
    'ZipCode'    => 'Artesaos\ZipCode\Facades\ZipCode',

),

How to Use

To use is very simple, pass the ZIP and calls the various types of returns, like this:

Facade

Add namespace:

use Artesaos\ZipCode\Facades\ZipCode;

Code Example

$zipCodeInfo = ZipCode::find('01414-001');

Helper

$zipCodeInfo = zipcode('01414000');

Injection

Add Namespace

use Artesaos\ZipCode\Contracts\ZipCodeContract;

Code Example

public function index(ZipCodeContract $zipcode)
{
      $zipCodeInfo = $zipcode->find('01414000');

Traits

Add Namespace

use Artesaos\ZipCode\ZipCodeTrait;

Code Example

class WelcomeController extends Controller {

    use ZipCodeTrait;

    public function index()
    {
            $zipCodeInfo =  $this->zipcode('01414000');

Summary of How to Use

Code

$zipCodeInfo = ZipCode::find('01414000', false); //Facade
$zipCodeInfo = $zipcode->find('01414000', false); //Contracts
$zipCodeInfo = zipcode('01414000', false); // Helper
$zipCodeInfo = $this->zipcode('01414000', true); //Traist

Return

The return can be null or class instance ZipCodeInfo (Artesaos\ZipCode\ZipCodeInfo)

Methods ZipCodeInfo:

  • Json => getJson()
if ($zipCodeInfo) 
{
    $zipCodeInfo->getJson();

    {
        "cep": "01414-001",
        "logradouro": "Rua Haddock Lobo",
        "bairro": "Cerqueira César",
        "localidade": "São Paulo",
        "uf": "SP",
        "ibge": "3550308", 
        "complemento": ""
    }
}
  • Array => getArray()
if ($zipCodeInfo) 
{
    $zipCodeInfo->getArray();

    Array
    (
        [cep] => 01414-001
        [logradouro] => Rua Haddock Lobo
        [bairro] => Cerqueira César
        [localidade] => São Paulo
        [uf] => SP
        [ibge] => 3550308,
        [complemento] => 
    )
}
  • Object => getObject()
if ($zipCodeInfo) 
{
    $zipCodeInfo->getObject();

    stdClass Object
    (
        [cep] => 01414-001
        [logradouro] => Rua Haddock Lobo
        [bairro] => Cerqueira César
        [localidade] => São Paulo
        [uf] => SP
        [ibge] => 3550308
        [complemento] => 
    )
}

Renew item from cache

$zipCodeInfo  = ZipCode::find('01414001', true);            
if ($zipCodeInfo) 
{
    $zipCodeInfo->getObject();

    stdClass Object
    (
        [cep] => 01414-001
        [logradouro] => Rua Haddock Lobo
        [bairro] => Cerqueira César
        [localidade] => São Paulo
        [uf] => SP
        [ibge] => 3550308
        [complemento] => 
    )
}