Skip to content
A cheeky little eloquent scope to get points within a certain radius area from a given latitude or longitude
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
README.md
composer.json

README.md

Laravel CloseTo

Laravel CloseTo is a cheeky little eloquent scope to get points within a certain radius area from a given latitude or longitude based off of the Haversine formula.

Installation

$ composer require jaejamesdev/laravelcloseto

Usage

Basic Example:

YourModel::closeTo($latitude, $longitude, $radiusInMiles);

The above example relies on your database having a column called 'latitude' and a column called 'longitude'. Should your database have a naming structure that is different to 'latitude' and 'longitude', no worries at all, you can use the below:

Advanced Example:

YourModel::closeTo($latitude, $longitude, $radiusInMiles, $latiudeColumnName, $longitudeColumnName);

Ordering By Distance:

If you want to get the closest results within a radius ordered by distance, this plugin can take care of that for you in a very simple way!

YourModel::closeTo($latitude, $longitude, $radiusInMiles)->orderBy('distance', 'asc');

Todos

- Add in option to convert between miles and kilometers.
- Improve documentation.

Issues & Requests

See the issues section on Github!

Follow Me

Why not give me a follow on twitter?

You can’t perform that action at this time.