codescheme / postcodes
UK Postcode API Facade for Laravel
Installs: 15 049
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 4
Forks: 2
Open Issues: 1
Requires
- php: ^5.5 || ^7.0
- guzzlehttp/guzzle: ~6.0
- guzzlehttp/psr7: ^1.3
- illuminate/support: 5.*
Requires (Dev)
- phpunit/phpunit: ^4.0 || ^5.5
This package is auto-updated.
Last update: 2019-09-20 07:23:50 UTC
README
A Laravel 5+ facade/service provider for the API methods at postcodes.io
- useful for UK postcode validation and reverse geocoding: that is, determining postcode from lat, long coordinates.
No fiddling around with api keys, authentication, necessary...
With thanks to https://postcodes.io
Installation
composer require codescheme/postcodes
For Laravel 5.5 Postcodes will be automatically discovered.
Edit /config/app.php
and add the service provider to your providers
array.
'providers' => [ Codescheme\Postcodes\PostcodeServiceProvider::class, ]
Also here, add the alias:
'aliases' => [ 'Postcode' => Codescheme\Postcodes\Facades\Postcode::class, ]
Basic Example Laravel Usage
Return data for a given postcode
Route::get('/postcode', function(){ $data = Postcode::postcodeLookup('SE21 8JL'); print_r($data); return null; });
Methods
Postcode::validate('SE31 9AX'); //returns boolean
Postcode::postcodeLookup('SE21 8JL');
Postcode::nearest('SE21 8JL');
Postcode::reverseGeocode(-0.397913, 51.44015); // long,lat
Postcode::autocomplete('RG1 3');
Postcode::outcodeLookup('SE21');
$postcodes = ['OX49 5NU', 'M32 0JG', 'NE30 1DP'];
Postcode::postcodeLookupBulk($postcodes);
$coordinates = [
['longitude' => 0.629834723775309, 'latitude' => 51.7923246977375],
['longitude' => -2.49690382054704, 'latitude' => 53.5351312861402]
];
Postcode::reverseGeocodeBulk($coordinates);
Testing
$ composer test