| Package Data | |
|---|---|
| Maintainer Username: | malhal |
| Maintainer Contact: | composer@malcolmhall.com (Malcolm Hall) |
| Package Create Date: | 2016-10-01 |
| Package Last Update: | 2025-05-04 |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-27 15:02:57 |
| Package Statistics | |
|---|---|
| Total Downloads: | 330,997 |
| Monthly Downloads: | 5,473 |
| Daily Downloads: | 121 |
| Total Stars: | 286 |
| Total Watchers: | 11 |
| Total Forks: | 53 |
| Total Open Issues: | 9 |
Easily add longitude and latitude columns to your records and use inherited functionality for calculating distances.
First either update your database or add this to a migration for each model:
$table->double('longitude');
$table->double('latitude');
Finally in your model use:
use Geographical;
Find the distance to all the entries in your table from a particular location.
$query = Model::distance($latitude, $longitude);
$asc = $query->orderBy('distance', 'ASC')->get();
Find all the entries in your table inside a circular geo-fence.
$query = Model::geofence($latitude, $longitude, $inner_radius, $outer_radius);
$all = $query->get();
The default unit of distance is miles. You can change it to kilometers by putting this in your model
protected static $kilometers = true;
Eloquent\Builder object so that you can add optional conditions if you want.distance as an aggregate column in the result.
(Aggregate columns cannot be used in WHERE, use HAVING to execute any condition.)const LATITUDE = 'lat';
const LONGITUDE = 'lng';
PHP 5.6.4+ and Laravel 5+ are required.
To get the latest version of Laravel Geographical, simply require the project using Composer:
$ composer require malhal/laravel-geographical