Search for addresses by zip code using the ViaCEP REST API.
Via Composer
$ composer require flyingluscas/viacep-php
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"
}
*/
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',
]
]
*/
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email lucas.pires.mattos@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.