PHPackages                             leitom\_7/geo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. leitom\_7/geo

ActiveLibrary[Caching](/categories/caching)

leitom\_7/geo
=============

A package that leverage redis geospatial functionality for super fast searching and integrates beautifully with Laravel.

v1.1.0(6y ago)011MITPHPPHP ^7.2

Since Aug 4Pushed 6y agoCompare

[ Source](https://github.com/nifengfanpan/geo)[ Packagist](https://packagist.org/packages/leitom_7/geo)[ Docs](https://github.com/leitom/geospatial)[ RSS](/packages/leitom-7-geo/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (4)Used By (0)

A package that uses Redis geospatial functions for providing super fast searches.
=================================================================================

[](#a-package-that-uses-redis-geospatial-functions-for-providing-super-fast-searches)

[![Latest Version on Packagist](https://camo.githubusercontent.com/420a1f64cfcf82fcdbb4ef56ad7a181339789feaa120bca2741a036391218f97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6569746f6d2f67656f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/leitom/geo)[![Build Status](https://camo.githubusercontent.com/ee74a4a29d4f28e1b6fcdf8a89f0a2ba7447b1fede38bd396acb50ab68bbd1b2/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6c6569746f6d2f67656f2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/leitom/geo)[![Quality Score](https://camo.githubusercontent.com/6255c77ebe79251d07296f3133d6ce909020b268956ac702672c73024ad9f046/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6c6569746f6d2f67656f2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/leitom/geo)[![Total Downloads](https://camo.githubusercontent.com/f8c02c0a4e6530ac5160180baf0c402fb9dad28aa74b07b1c50d1328d1f4ab77/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6569746f6d2f67656f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/leitom/geo)

This package makes it easy to add geospatial to your Laravel applications. It uses Redis built in geospatial features and combine this with your Laravel Models in an elegant way.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require leitom/geo
```

Usage
-----

[](#usage)

The package comes with a simple trait thats integrates with Laravel Eloquent models but also a facade to interact with the different geospatial functions.

### Laravel Eloquent integration

[](#laravel-eloquent-integration)

All you have to do when integrating this package with one or more of your Eloquent models is to use the `Leitom\Geo\HasGeoAbilities` trait. This trait will take care of keeping the Redis index in sync with your models due to the use of a model observer so you dont have to think about it. Each time you create, save or delete a model the Redis index will be updated to reflect the changes.

```
use Leitom\Geo\HasGeoAbilities;

class User extends Model
{
    use HasGeoAbilities;

    protected $fillable = ['id', 'name', 'longitude', 'latitude'];
}
```

### Search

[](#search)

Here we perform a search with Longitude, Latitude and Radius. The unit of the radius is configured in the configuration file, default km = kilometers. With the 4. argument to the `geoSearch` function you can specify the sorting, default `ASC`.

```
$users = User::geoSearch(-115.17258, 36.11996, 10)->get();
```

The package adds two attributes to every model who implements the HasGeoAbilities. We add the unit and distance wich you can display to the end user.

```
$user->geoUnit // km
$user->geoDistance; // 0.999
```

The `toArray()` function is also overrided so that these two attributes would be loaded.

```
[
    'geo_unit' => 'km',
    'geo_distance' => 0.999,
]
```

### Find distance between two models

[](#find-distance-between-two-models)

To find the distance between two models you can use the `geoDistanceFrom` function on a given model

```
$userA = User::findOrFail(1);
$userB = User::findOrFail(2);

$userA->geoDistanceFrom($userB) // ['unit' => 'km', 'distance' => 0.999]
```

### Get the nearest models

[](#get-the-nearest-models)

```
$userA = User::findOrFail(1);
$userB = User::findOrFail(2);

$users = $userA->geoNearest()->paginate(5);
```

### Perform a search via the `Geo` facade

[](#perform-a-search-via-the-geo-facade)

```
$locations = Leitom\Geo\Facades\Geo::index('cars')->search(-115.17258, 36.11996, 10);
```

### Get the distance between two locations

[](#get-the-distance-between-two-locations)

```
$locationA = new Leitom\Geo\Coordinate('my-car', -115.17087, 36.12306);
$locationB = new Leitom\Geo\Coordinate('robins-car', -115.171971, 36.120609);

Leitom\Geo\Facades\Geo::index('cars')->between($locationA, $locationB); // 0.2900
```

### Get a list of the nearest locations from a given location

[](#get-a-list-of-the-nearest-locations-from-a-given-location)

```
$locationA = new Leitom\Geo\Coordinate('my-car', -115.17087, 36.12306);

Leitom\Geo\Facades\Geo::index('cars')->from($locationA, 10, 'ASC'); // [['my-car' => 0], ['your-car' => 0.2900]]
```

### Add a coordinate to an index

[](#add-a-coordinate-to-an-index)

```
$locationA = new Leitom\Geo\Coordinate('my-car', -115.17087, 36.12306);

Leitom\Geo\Facades\Geo::index('cars')->add($locationA);
```

### Add multiple coordinates to an index

[](#add-multiple-coordinates-to-an-index)

```
$locationA = new Leitom\Geo\Coordinate('my-car', -115.17087, 36.12306);
$locationB = new Leitom\Geo\Coordinate('robins-car', -115.171971, 36.120609);

Leitom\Geo\Facades\Geo::index('cars')->add($locationA, $locationB);

Leitom\Geo\Facades\Geo::index('cars')->add([$locationA, $locationB]);
```

### Remove coordinates from an index

[](#remove-coordinates-from-an-index)

```
Leitom\Geo\Facades\Geo::index('cars')->remove('my-car');

Leitom\Geo\Facades\Geo::index('cars')->remove('my-car', 'robins-car');
```

### Import and Remove existing models

[](#import-and-remove-existing-models)

The package include two commands to handle import and remove models from the Redis index. This is usefull if you integrate this package in an existing project.

```
php artisan geo:import App\User
```

```
php artisan geo:remove App\User
```

### Testing

[](#testing)

Ensure you have Redis installed. If you are not using the default configuration for Redis you can change environment variables in the phpunit.xml file.

```
composer test
```

When testing you own application logic you should include the `Leitom\Geo\Tests\RefreshGeo` trait. This will ensure that you start with a fresh Redis index inside your tests. Just like the built in `RefreshDatabase` trait in Laravel.

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Tommy Leirvik](https://github.com/leitom)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~100 days

Total

3

Last Release

2271d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/19427115?v=4)[完颜不破](/maintainers/junshenshi)[@junshenshi](https://github.com/junshenshi)

---

Top Contributors

[![leitom](https://avatars.githubusercontent.com/u/222862?v=4)](https://github.com/leitom "leitom (14 commits)")[![nifengfanpan](https://avatars.githubusercontent.com/u/50734943?v=4)](https://github.com/nifengfanpan "nifengfanpan (4 commits)")

---

Tags

laravelredisgeoleitom

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/leitom-7-geo/health.svg)

```
[![Health](https://phpackages.com/badges/leitom-7-geo/health.svg)](https://phpackages.com/packages/leitom-7-geo)
```

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975163.6k2](/packages/awssat-laravel-visits)[monospice/laravel-redis-sentinel-drivers

Redis Sentinel integration for Laravel and Lumen.

103830.5k](/packages/monospice-laravel-redis-sentinel-drivers)[encore/redis-manager

Redis manager for laravel

25243.1k](/packages/encore-redis-manager)[namoshek/laravel-redis-sentinel

An extension of Laravels Redis driver which supports connecting to a Redis master through Redis Sentinel.

38679.0k](/packages/namoshek-laravel-redis-sentinel)[yangusik/laravel-balanced-queue

Laravel queue management with load balancing between partitions (user groups)

786.4k](/packages/yangusik-laravel-balanced-queue)[ginnerpeace/laravel-redis-lock

Simple redis distributed locks for Laravel.

15114.4k](/packages/ginnerpeace-laravel-redis-lock)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
