PHPackages                             mammutgroup/laravel-spatial - 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. mammutgroup/laravel-spatial

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

mammutgroup/laravel-spatial
===========================

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

3.1.3(9y ago)2221MITPHPPHP &gt;=5.5

Since Mar 21Pushed 9y ago2 watchersCompare

[ Source](https://github.com/mammutgroup/laravel-spatial)[ Packagist](https://packagist.org/packages/mammutgroup/laravel-spatial)[ RSS](/packages/mammutgroup-laravel-spatial/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (8)Versions (33)Used By (0)

Laravel Mysql Geometry extension
================================

[](#laravel-mysql-geometry-extension)

[![Build Status](https://camo.githubusercontent.com/ea2a548689ab90dffff6985feb22a5e2c5cf9facd58c72a91fdafe40d86d31fb/68747470733a2f2f7472617669732d63692e6f72672f6e6a626172726574742f6c61726176656c2d706f73746769732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/njbarrett/laravel-postgis.svg?branch=master)[![Code Climate](https://camo.githubusercontent.com/879839c69b421d532b7d69ce0fe5442d72461160edc48e022f0619c7e1758539/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6e6a626172726574742f6c61726176656c2d706f73746769732f6261646765732f6770612e737667)](https://codeclimate.com/github/njbarrett/laravel-postgis)[![Coverage Status](https://camo.githubusercontent.com/1b7cb57d4a165b74c65d0dcc96d1fdcd19995539f6ae3d62ad3f1df6cfb4a804/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6e6a626172726574742f6c61726176656c2d706f73746769732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/njbarrett/laravel-postgis?branch=master)

Features
--------

[](#features)

- Work with geometry classes instead of arrays. (`$myModel->myPoint = new Point(1,2)`)
- Adds helpers in migrations. (`$table->polygon('myColumn')`)

### Future plans

[](#future-plans)

- Geometry functions on the geometry classes (contains(), equals(), distance(), etc… (HELP!))

Versions
--------

[](#versions)

Use 2.\* for Laravel 5.1.\*
Use 3.\* for Laravel 5.2.\*

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

[](#installation)

```
composer require phaza/laravel-postgis

```

Next add the DatabaseServiceProvider to your `config/app.php` file.

```
'Mammutgroup\LaravelPostgis\DatabaseServiceProvider',

```

That's all.

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 Mammutgroup\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');
            $table->polygon('polygon');
            $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.

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

class Location extends Model
{
    use PostgisTrait;

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

    protected $postgisFields = [
        'location',
        'polygon',
    ];

}

$location1 = new Location();
$location1->name = 'Googleplex';
$location1->address = '1600 Amphitheatre Pkwy Mountain View, CA 94043';
$location1->location = new Point(37.422009, -122.084047);
$location1->save();

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

Available geometry classes:

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

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 60.7% 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 ~22 days

Recently: every ~41 days

Total

30

Last Release

3460d ago

Major Versions

0.2 → 1.02015-03-24

1.2 → 2.02015-04-13

2.16 → 3.02016-01-26

2.17 → 3.12016-05-21

2.18 → 5.1.x-dev2016-08-17

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/904829?v=4)[Honarkhah](/maintainers/honarkhah)[@honarkhah](https://github.com/honarkhah)

---

Top Contributors

[![phaza](https://avatars.githubusercontent.com/u/4553?v=4)](https://github.com/phaza "phaza (54 commits)")[![metalmatze](https://avatars.githubusercontent.com/u/872251?v=4)](https://github.com/metalmatze "metalmatze (21 commits)")[![njbarrett](https://avatars.githubusercontent.com/u/241407?v=4)](https://github.com/njbarrett "njbarrett (6 commits)")[![sayadaazami](https://avatars.githubusercontent.com/u/11436168?v=4)](https://github.com/sayadaazami "sayadaazami (2 commits)")[![jonnybarnes](https://avatars.githubusercontent.com/u/108303?v=4)](https://github.com/jonnybarnes "jonnybarnes (2 commits)")[![honarkhah](https://avatars.githubusercontent.com/u/904829?v=4)](https://github.com/honarkhah "honarkhah (2 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)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mammutgroup-laravel-spatial/health.svg)

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

###  Alternatives

[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.1M23](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.4M2](/packages/glushkovds-phpclickhouse-laravel)[laravel-liberu/laravel-gedcom

A package that converts gedcom files to Eloquent models

782.5k1](/packages/laravel-liberu-laravel-gedcom)[itpathsolutions/dbstan

Database Standardization and Analysis Tool for Laravel

442.1k](/packages/itpathsolutions-dbstan)[ntanduy/cloudflare-d1-database

Cloudflare D1 database driver for Laravel — full Eloquent &amp; Query Builder support.

276.8k](/packages/ntanduy-cloudflare-d1-database)

PHPackages © 2026

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