PHP code example of juststeveking / laravel-postcodes
1. Go to this page and download the library: Download juststeveking/laravel-postcodes library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
juststeveking / laravel-postcodes example snippets
use JustSteveKing\LaravelPostcodes\Service\PostcodeService;
class SomeController extends Controller
{
protected $postcodes;
public function __construct(PostcodeService $service)
{
$this->postcodes = $service;
}
public function store(Request $request)
{
// validation using example above
$location = $this->postcodes->getPostcode($request->postcode);
}
}
class SomeController extends Controller
{
public function store(Request $request)
{
// validation using example above
$location = Postcode::getPostcode($request->postcode);
}
}
$service = resolve(PostcodeService::class);
$service->validate('AB10 1AB');
// You can also use the facade:
Postcode::validate('AB10 1AB');
$service = resolve(PostcodeService::class);
$service->validate('AB10 1AB');
// You can also use the facade:
Postcode::validate('AB10 1AB');
$service = resolve(PostcodeService::class);
$service->getPostcode('AB10 1AB');
// You can also use the facade:
Postcode::getPostcode('AB10 1AB');
$service = resolve(PostcodeService::class);
$service->getPostcodes([
'AB10 1AB',
'AB10 1AF',
'AB10 1AG',
]);
// You can also use the facade:
Postcode::getPostcodes([
'AB10 1AB',
'AB10 1AF',
'AB10 1AG',
]);
$service = resolve(PostcodeService::class);
$service->nearestPostcodesForGivenLngAndLat(
0.629806,
51.792326
);
// You can also use the facade:
Postcode::nearestPostcodesForGivenLngAndLat(
0.629806,
51.792326
);
$service = resolve(PostcodeService::class);
$service->nearest('AB10 1AB');
// You can also use the facade:
Postcode::nearest('AB10 1AB');
$service = resolve(PostcodeService::class);
$service->autocomplete('AB10');
// You can also use the facade:
Postcode::autocomplete('AB10');
$service = resolve(PostcodeService::class);
$service->query('AB10 1AB');
// You can also use the facade:
Postcode::query('AB10 1AB');
$service = resolve(PostcodeService::class);
$service->getTerminatedPostcode('AB1 0AA');
// You can also use the facade:
Postcode::getTerminatedPostcode('AB1 0AA');
$service = resolve(PostcodeService::class);
$service->getOutwardCode('N11');
// You can also use the facade:
Postcode::getOutwardCode('N11');
$service = resolve(PostcodeService::class);
$limit = 80; // Limit needs to be less than 100
$radius = 15000; // Radius needs to be less than 25000
$service->getNearestOutwardCode('N11', $limit, $radius);
// You can also use the facade:
Postcode::getNearestOutwardCode('N11', $limit, $radius);
$service = resolve(PostcodeService::class);
$service->nearestOutwardCodesForGivenLngAndLat(
0.629806,
51.792326
);
// You can also use the facade:
Postcode::nearestOutwardCodesForGivenLngAndLat(
0.629806,
51.792326
);