v1.12.0 2021-05-22 16:08 UTC

This package is auto-updated.

Last update: 2023-03-01 01:01:48 UTC


This package implemented to calculate or check the distance between the point and other points from the database and also retrieve points in an area, be it an arbitrary polygon or a circle, and this is a fork of DigitalCloud Laravel-Posgis.

Implemented function to search for points in a geoJSON polygon: whereCovers


PHP >=7.1.3 and Laravel ^7.x are required.

the package used Laravel postgis extension to deal with postgres database points in laravel, so if need more details or how to enable postgis extension in php see previous link.

To get the latest version of Laravel PostGIS, simply require the project using Composer:

composer require jeorgy/laravel-postgis


1 . First of all use Postgis trait in your model


namespace App;

use Jeorgy\LaravelPostgis\Postgis;
use Illuminate\Database\Eloquent\Model;

class UserLocation extends Model
    use Postgis;

2 . By default package assume that the name of the point column is location if you want to change it override location variable on your model

protected $location = "my_column";

3 . Also By default package assume that the unit of distance is meter if you want to change it override unit variable on your model

 protected $unit = "km"; //units avialble [mile, km, meter]


1. withDistance

get the distance between point and other points

UserLocation::withDistance(new Point($latitude,$longitude))
            ->whereIn("user_id", $users)

2. whereDistance and orWhereDistance

check the distance between a point and other points in database

       UserLocation::whereDistance(new Point($latitude,$longitude), ">", 50)
            ->whereIn("user_id", $users)

3. whereCovers and orWhereCovers

get points inside a geoJSON polygon