Skip to content
Search for Brazilian addresses by zip code using the ViaCEP REST API.
PHP
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci circleci: add vendor cache Aug 24, 2019
.github chore: add .github folder Aug 24, 2019
src chore: refactor ZipCode class Aug 25, 2019
tests chore: refactor ZipCode class Aug 25, 2019
.codecov.yml codecov: add config file Jul 6, 2018
.editorconfig first commit Nov 4, 2016
.gitattributes first commit Nov 4, 2016
.gitignore added address class Nov 4, 2016
CHANGELOG.md changelog: add version 2.0.0 Aug 25, 2019
CONDUCT.md first commit Nov 4, 2016
CONTRIBUTING.md first commit Nov 4, 2016
LICENSE.md first commit Nov 4, 2016
README.md readme: update readme Aug 25, 2019
composer.json feature: add search by address Aug 24, 2019
phpunit.xml.dist phpunit: remove reports Aug 24, 2019

README.md

ViaCEP PHP SDK

Latest Version on Packagist CircleCI Codecov Software License Total Downloads

Search for addresses by zip code using the ViaCEP REST API.

Install

Via Composer

$ composer require flyingluscas/viacep-php

Usage

findByZipCode

Find address by zip code.

use FlyingLuscas\ViaCEP\ViaCEP;

$viacep = new ViaCEP;

$address = $viacep->findByZipCode('01001-000')->toArray();

/*
Should return something like this:

[
    'zipCode' => '01001-000',
    'street' => 'Praça da Sé',
    'complement' => 'lado ímpar',
    'neighborhood' => 'Sé',
    'city' => 'São Paulo',
    'state' => 'SP',
    'ibge' => '3550308',
]
*/

$address = $viacep->findByZipCode('01001-000')->toJson();

/*
Should return something like this:

{
    "zipCode": "01001-000",
    "street": "Praça da Sé",
    "complement": "lado ímpar",
    "neighborhood": "Sé",
    "city": "São Paulo",
    "state": "SP",
    "ibge": "3550308"
}
*/

findByStreetName

Search for addresses using state, city and a street name.

use FlyingLuscas\ViaCEP\ViaCEP;

$viacep = new ViaCEP;

$addresses = $viacep->findByStreetName('SP', 'São Paulo', 'Gomes de Carvalho');

/*
Should return something like this:

[
    [
        'zipCode' => '01001-000',
        'street' => 'Praça da Sé',
        'complement' => 'lado ímpar',
        'neighborhood' => 'Sé',
        'city' => 'São Paulo',
        'state' => 'SP',
        'ibge' => '3550308',
    ],
    [
        'zipCode' => '01001-000',
        'street' => 'Praça da Sé',
        'complement' => 'lado ímpar',
        'neighborhood' => 'Sé',
        'city' => 'São Paulo',
        'state' => 'SP',
        'ibge' => '3550308',
    ]
]
*/

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email lucas.pires.mattos@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

You can’t perform that action at this time.