https://github.com/axkuechler/laravel-geoly
Perform fast and efficient radius searches on your Laravel Eloquent models.
https://github.com/axkuechler/laravel-geoly
distance distance-calculation eloquent geolocation laravel latitude latitude-and-longitude longitude model radius search
Last synced: 3 months ago
JSON representation
Perform fast and efficient radius searches on your Laravel Eloquent models.
- Host: GitHub
- URL: https://github.com/axkuechler/laravel-geoly
- Owner: axkuechler
- License: mit
- Created: 2019-12-08T20:20:47.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-20T07:22:21.000Z (about 5 years ago)
- Last Synced: 2026-01-02T10:50:04.252Z (6 months ago)
- Topics: distance, distance-calculation, eloquent, geolocation, laravel, latitude, latitude-and-longitude, longitude, model, radius, search
- Language: PHP
- Size: 14.6 KB
- Stars: 42
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Geoly
[](https://packagist.org/packages/akuechler/laravel-geoly)

[](https://github.styleci.io/repos/226726169)
[](https://github.com/akuechler/laravel-geoly/blob/master/LICENSE)
Perform fast and efficient radius searches on your Laravel Eloquent models.
Laravel Geoly provides a convenient way for your Laravel Eloquent models to query in a certain radius around a position. It is lightning fast by using a bounding box to cut down the possible results and calculating the distance only on the remaining subset. Laravel Geoly works on both MySQL and PostgreSQL.
## Requirements
* PHP 7.1+
* Laravel 5+
* Tested on MySQL and PostgreSQL
## Installation
Simply require the project via composer:
`$ composer require akuechler/laravel-geoly`
## How to use
Geoly assumes the two columns `latitude` and `longitude` on your eloquent model. Simply add them to your migration if not present yet.
```php
$table->double('latitude');
$table->double('longitude');
```
If you prefer to use other names for your database columns, specify them in your model.
```php
const LATITUDE = 'lat';
const LONGITUDE = 'lng';
```
Use the Geoly package within your Eloquent model.
```php
class YourModel extends Model
{
use Geoly;
...
}
```
To search for all models within a specific radius around a position, add the `radius` scope to your query.
```php
$query = YourModel::radius($latitude, $longitude, $radius);
$query->get();
```
## Credits
This project is heavily inspired by [Laravel Geographical](https://github.com/malhal/Laravel-Geographical) and [Movable Type Scripts](https://www.movable-type.co.uk/) article on [Selecting points within a bounding circle](https://www.movable-type.co.uk/scripts/latlong-db.html).