PHPackages                             lscortesc/laravel-postgis - 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. [Database &amp; ORM](/categories/database)
4. /
5. lscortesc/laravel-postgis

ActiveLibrary[Database &amp; ORM](/categories/database)

lscortesc/laravel-postgis
=========================

Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models

5.2(5y ago)0689MITPHPPHP ^7.3

Since Mar 21Pushed 5y agoCompare

[ Source](https://github.com/lscortesc/laravel-postgis)[ Packagist](https://packagist.org/packages/lscortesc/laravel-postgis)[ RSS](/packages/lscortesc-laravel-postgis/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (7)Versions (48)Used By (0)

Laravel Wrapper for PostgreSQL's Geo-Extension Postgis
======================================================

[](#laravel-wrapper-for-postgresqls-geo-extension-postgis)

[![Build Status](https://github.com/mstaack/laravel-postgis/workflows/Test%20Suite/badge.svg)](https://github.com/mstaack/laravel-postgis/workflows/Test%20Suite/badge.svg)

Features
--------

[](#features)

- Work with geometry classes instead of arrays.

```
$model->myPoint = new Point(1,2);  //lat, long
```

- Adds helpers in migrations.

```
$table->polygon('myColumn');
```

Warning
-------

[](#warning)

This Package has been moved to a new owner and aims for Laravel 6/7/8 and PHP 7 support only soon!

Replace all your references to the new namespace:

```
MStaack\LaravelPostgis

```

Thanks to :

-
-
-

Fluent in Laravel Packages and Postgres/Postgis? Consider contributing! We are looking for anyone that wants to help out!

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

[](#installation)

- Use 3.\* for Laravel 5

```
composer require "mstaack/laravel-postgis:3.*"
```

- Use 5.\* for Laravel 6/7/8

```
composer require mstaack/laravel-postgis
```

For laravel &gt;=5.5 that's all. This package supports Laravel new [Package Discovery](https://laravel.com/docs/5.5/packages#package-discovery).

If you are using Laravel &lt; 5.5, you also need to add the DatabaseServiceProvider to your `config/app.php` file.

```
'MStaack\LaravelPostgis\DatabaseServiceProvider',
```

Usage
-----

[](#usage)

First of all, make sure to enable postgis.

```
CREATE EXTENSION postgis;

```

To verify that postgis is enabled

```
SELECT postgis_full_version();

```

### Migrations

[](#migrations)

Now create a model with a migration by running

```
php artisan make:model Location

```

If you don't want a model and just a migration run

```
php artisan make:migration create_locations_table

```

Open the created migrations with your editor.

```
use Illuminate\Database\Migrations\Migration;
use MStaack\LaravelPostgis\Schema\Blueprint;

class CreateLocationsTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('locations', function(Blueprint $table)
        {
            $table->increments('id');
            $table->string('name');
            $table->string('address')->unique();
            $table->point('location'); // GEOGRAPHY POINT column with SRID of 4326 (these are the default values).
            $table->point('location2', 'GEOGRAPHY', 4326); // GEOGRAPHY POINT column with SRID of 4326 with optional parameters.
            $table->point('location3', 'GEOMETRY', 27700); // GEOMETRY column with SRID of 27700.
            $table->polygon('polygon'); // GEOGRAPHY POLYGON column with SRID of 4326.
            $table->polygon('polygon2', 'GEOMETRY', 27700); // GEOMETRY POLYGON column with SRID of 27700.
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('locations');
    }

}
```

Available blueprint geometries:

- point
- multipoint
- linestring
- multilinestring
- polygon
- multipolygon
- geometrycollection

other methods:

- enablePostgis
- disablePostgis

### Models

[](#models)

All models which are to be PostGis enabled **must** use the *PostgisTrait*.

You must also define an array called `$postgisFields` which defines what attributes/columns on your model are to be considered geometry objects. By default, all attributes are of type `geography`. If you want to use `geometry` with a custom SRID, you have to define an array called `$postgisTypes`. The keys of this assoc array must match the entries in `$postgisFields` (all missing keys default to `geography`), the values are assoc arrays, too. They must have two keys: `geomtype` which is either `geography` or `geometry` and `srid` which is the desired SRID. **Note**: Custom SRID is only supported for `geometry`, not `geography`.

```
use Illuminate\Database\Eloquent\Model;
use MStaack\LaravelPostgis\Eloquent\PostgisTrait;
use MStaack\LaravelPostgis\Geometries\Point;

class Location extends Model
{
    use PostgisTrait;

    protected $fillable = [
        'name',
        'address'
    ];

    protected $postgisFields = [
        'location',
        'location2',
        'location3',
        'polygon',
        'polygon2'
    ];

    protected $postgisTypes = [
        'location' => [
            'geomtype' => 'geography',
            'srid' => 4326
        ],
        'location2' => [
            'geomtype' => 'geography',
            'srid' => 4326
        ],
        'location3' => [
            'geomtype' => 'geometry',
            'srid' => 27700
        ],
        'polygon' => [
            'geomtype' => 'geography',
            'srid' => 4326
        ],
        'polygon2' => [
            'geomtype' => 'geometry',
            'srid' => 27700
        ]
    ]
}

$linestring = new LineString(
    [
        new Point(0, 0),
        new Point(0, 1),
        new Point(1, 1),
        new Point(1, 0),
        new Point(0, 0)
    ]
);

$location1 = new Location();
$location1->name = 'Googleplex';
$location1->address = '1600 Amphitheatre Pkwy Mountain View, CA 94043';
$location1->location = new Point(37.422009, -122.084047);
$location1->location2 = new Point(37.422009, -122.084047);
$location1->location3 = new Point(37.422009, -122.084047);
$location1->polygon = new Polygon([$linestring]);
$location1->polygon2 = new Polygon([$linestring]);
$location1->save();

$location2 = Location::first();
$location2->location instanceof Point // true
```

Available geometry classes:

- Point
- MultiPoint
- LineString
- MultiLineString
- Polygon
- MultiPolygon
- GeometryCollection

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~48 days

Recently: every ~97 days

Total

43

Last Release

2052d ago

Major Versions

2.18 → 3.1.12017-01-16

3.1.1 → 5.1.x-dev2017-05-21

2.19 → 3.1.22017-05-21

3.6 → 4.02019-09-05

4.0.1 → 5.02020-03-11

PHP version history (3 changes)0.1PHP &gt;=5.5

5.0PHP &gt;=7.1

5.2PHP ^7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/80be3f013565527695a5f5668276869318b37c49912af79263f715c1e069870e?d=identicon)[lscortesc](/maintainers/lscortesc)

---

Top Contributors

[![phaza](https://avatars.githubusercontent.com/u/4553?v=4)](https://github.com/phaza "phaza (54 commits)")[![njbarrett](https://avatars.githubusercontent.com/u/241407?v=4)](https://github.com/njbarrett "njbarrett (34 commits)")[![metalmatze](https://avatars.githubusercontent.com/u/872251?v=4)](https://github.com/metalmatze "metalmatze (21 commits)")[![v1r0x](https://avatars.githubusercontent.com/u/9248714?v=4)](https://github.com/v1r0x "v1r0x (20 commits)")[![nickbarrettjb](https://avatars.githubusercontent.com/u/16773808?v=4)](https://github.com/nickbarrettjb "nickbarrettjb (10 commits)")[![mstaack](https://avatars.githubusercontent.com/u/10169509?v=4)](https://github.com/mstaack "mstaack (9 commits)")[![dena-a](https://avatars.githubusercontent.com/u/4950968?v=4)](https://github.com/dena-a "dena-a (3 commits)")[![grimzy](https://avatars.githubusercontent.com/u/1837678?v=4)](https://github.com/grimzy "grimzy (3 commits)")[![mirzap](https://avatars.githubusercontent.com/u/991967?v=4)](https://github.com/mirzap "mirzap (2 commits)")[![luizguilhermefr](https://avatars.githubusercontent.com/u/6135939?v=4)](https://github.com/luizguilhermefr "luizguilhermefr (2 commits)")[![jonnybarnes](https://avatars.githubusercontent.com/u/108303?v=4)](https://github.com/jonnybarnes "jonnybarnes (2 commits)")[![ajthinking](https://avatars.githubusercontent.com/u/3457668?v=4)](https://github.com/ajthinking "ajthinking (2 commits)")[![vlktomas](https://avatars.githubusercontent.com/u/13019480?v=4)](https://github.com/vlktomas "vlktomas (1 commits)")[![chrudosvorlicek](https://avatars.githubusercontent.com/u/4454957?v=4)](https://github.com/chrudosvorlicek "chrudosvorlicek (1 commits)")[![davidpiesse](https://avatars.githubusercontent.com/u/800650?v=4)](https://github.com/davidpiesse "davidpiesse (1 commits)")[![Gerzhelinazhit](https://avatars.githubusercontent.com/u/30827553?v=4)](https://github.com/Gerzhelinazhit "Gerzhelinazhit (1 commits)")[![gueroverde](https://avatars.githubusercontent.com/u/1765489?v=4)](https://github.com/gueroverde "gueroverde (1 commits)")[![JaakkoTulkki](https://avatars.githubusercontent.com/u/6376118?v=4)](https://github.com/JaakkoTulkki "JaakkoTulkki (1 commits)")[![jessedc](https://avatars.githubusercontent.com/u/17407?v=4)](https://github.com/jessedc "jessedc (1 commits)")[![kohenkatz](https://avatars.githubusercontent.com/u/88755?v=4)](https://github.com/kohenkatz "kohenkatz (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lscortesc-laravel-postgis/health.svg)

```
[![Health](https://phpackages.com/badges/lscortesc-laravel-postgis/health.svg)](https://phpackages.com/packages/lscortesc-laravel-postgis)
```

###  Alternatives

[limenet/laravel-mysql-spatial

MySQL spatial data types extension for Laravel.

1214.2k](/packages/limenet-laravel-mysql-spatial)

PHPackages © 2026

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