Package Data | |
---|---|
Maintainer Username: | Laralabs |
Maintainer Contact: | matt@laralabs.uk (Matt Clinton) |
Package Create Date: | 2017-03-17 |
Package Last Update: | 2024-03-13 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-19 03:03:50 |
Package Statistics | |
---|---|
Total Downloads: | 2,086 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 2 |
Total Forks: | 2 |
Total Open Issues: | 0 |
Postcode distance sorting package for Laravel Collections.
UNITED KINGDOM POSTCODES ONLY
Require the package in the composer.json
of your project.
composer require laralabs/geo-sorter
Publish the configuration file.
php artisan vendor:publish --tag=geosorter-config
Edit the configuration file and set your desired settings. If you want to use a custom database table name, set it here and cache your config before moving onto the next step.
Create the postcodes table by running the following command:
php artisan migrate
Once the database table has been created, run the following command to populate it with the latest UK Postcode District data.
php artisan geosorter:update
A helper function and facade are available, choose your preferred method. The sortByPostcode
method accepts three arguments, the third argument being an optional $sort
which can be used to override the sort order defined in the config.
Facade:
<?php
$collection = Addresses::all();
$postcode = 'B61 XYZ';
$collection = GeoSorter::sortByPostcode($collection, $postcode, 'ASC');
Helper:
<?php
$collection = Addresses::all();
$postcode = 'B61 XYZ';
$collection = geo_sorter()->sortByPostcode($collection, $postcode);
The above code would sort the Addresses collection in distance from the given postcode B61 XYZ
.
Ayeo/Geo is used to calculate the distance between coordinates.
Please raise an issue on GitHub if there is a problem.
This is open-sourced software licensed under the MIT License.