laralabs/geo-sorter

Postcode distance sorting package for Laravel Eloquent Collections.
2,103 2
Install
composer require laralabs/geo-sorter
Latest Version:3.1.0
PHP:^8.1
Laravel:12
Older releases:5 – 11
License:MIT
Last Updated:Feb 26, 2025
Links: GitHub  ·  Packagist
Maintainer: Laralabs

Geo Sorter for Laravel

Postcode distance sorting package for Laravel Collections.

UNITED KINGDOM POSTCODES ONLY

:rocket: Quick Start

Installation

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

Usage

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.

:pushpin: Credits

Ayeo/Geo is used to calculate the distance between coordinates.

:speech_balloon: Support

Please raise an issue on GitHub if there is a problem.

:key: License

This is open-sourced software licensed under the MIT License.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

644,549,754 9,698
laravel/framework

The Laravel Framework.

598,760,099 34,966
laravel/tinker

Powerful REPL for the Laravel framework.

507,193,856 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

423,477,751 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

399,241,428 4,660

Version History

Version Released PHP Laravel License
3.1.0 ^8.1 ^12.0 MIT
v3.0.4 ^7.3|^8.0 ^5.5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0 MIT
v3.0.3 ^7.3|^8.0 ^5.5|^6.0|^7.0|^8.0|^9.0|^10.0 MIT
v3.0.2 ^7.3|^8.0 ^5.5|^6.0|^7.0|^8.0 MIT
v3.0.1 ^7.3|^8.0 ^5.5|^6.0|^7.0|^8.0 MIT