Laravel Api Postcode Package
A laravel package for fetching Address details, (*1)
For more information see: https://api-postcode, (*2)
Requirements
Laravel 5.1 or later, (*3)
Installation
Installation is a quick 3 step process:, (*4)
- Download api-postcode-laravel using composer
- Enable the package in app.php
- Configure your Api Postcode credentials
Step 1: Download api-postcode-laravel using composer
Add api-postcode/api-postcode-laravel by running the command:, (*5)
composer require api-postcode/api-postcode-laravel
Step 2: Enable the package in app.php
Register the Service in: config/app.php, (*6)
``` php
ApiPostcode\ApiPostcodeServiceProvider::class,, (*7)
Optional - Register the Facade in: **config/app.php**
``` php
'aliases' => [
//...
'Postcode' => ApiPostcode\Facade\Postcode::class,
];
Step 3: Configure Api Postcode credentials
php artisan vendor:publish --provider="ApiPostcode\ApiPostcodeServiceProvider"
Add this in you .env file, (*8)
API_POSTCODE_TOKEN=secret-token-from-api-postcode
Usage
``` php
$address = app('api.postcode')->fetchAddress('1012JS', 1);, (*9)
$address->getStreet(); // Dam
$address->getCity(); // Amsterdam
$address->getHouseNumber(); // 1
$address->getZipCode(); // 1012JS
$address->getLongitude(); // 4.4584
$address->getLatitude(); // 52.2296, (*10)
Or use the Facade:
``` php
$address = Postcode::fetchAddress('1012JS', '1')
Or straight in routes:, (*11)
``` php
$router->get('postcode/{zipCode}/{number}', function ($zipCode, $number) {
return Postcode::fetchAddress($zipCode, $number);
});
````, (*12)