Laravel-getaddress provides a wrapper around getaddress.io for laravel 5.4 and up. This package is based on PeteLawrence/getaddress PHP library.
You can pull in the package via composer:
$ composer require szhorvath/laravel-getaddress
You need to add Szhorvath\GetAddress\GetAddressServiceProvider to your config/app.php
providers array:
Szhorvath\GetAddress\GetAddressServiceProvider::class,
Add the following environmental variable to your .env
file
GETADDRESSIO_API_KEY=your-api-key
You must publish the config file:
$ php artisan vendor:publish --provider="Szhorvath\GetAddress\GetAddressServiceProvider"
You can pull in the package via composer:
$ composer require szhorvath/laravel-getaddress
The package will automatically register itself.
Add the following environmental variable to your .env
file
GETADDRESSIO_API_KEY=your-api-key
You must publish the config file:
$ php artisan vendor:publish --provider="Szhorvath\GetAddress\GetAddressServiceProvider"
In a controller you can use the Facade. The GetAddress always returns an array
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Szhorvath\GetAddress\Facades\GetAddress;
class AddressController extends Controller
{
public function lookup()
{
$result = GetAddress::lookup('S20 8JH');
$longitude = $result->getLongitude();
$latitude = $result->getLatitude();
$addressList = $result->getAddresses();
foreach ($addressList as $key => $address) {
$line1 = $address->getLine1();
$line2 = $address->getLine2();
$line3 = $address->getLine3();
$line4 = $address->getLine4();
$town = $address->getTown();
$postalTown = $address->getPostalTown();
$normalisedTown = $address->getNormalisedTown();
$county = $address->getCounty();
#Full address as comma separated string
$csv = $address->toCsv();
}
#Or for a specific address you can pass the house number or name as second parameter
$result = GetAddress::lookup('S20 8JH', 5);
if ($address = $result->getAddress()) {
$town = $address->getTown();
};
}
}
Please see CHANGELOG for more information on what has changed recently.
$ composer test
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.