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

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

danhunsaker/laravel-spatial
===========================

Spatial data types extension for Laravel.

v1.0.1(5y ago)19.0k2[1 PRs](https://github.com/danhunsaker/laravel-spatial/pulls)MITPHPPHP ^7.2

Since Dec 23Pushed 4y ago2 watchersCompare

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

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

Laravel Spatial extension
=========================

[](#laravel-spatial-extension)

[![](https://camo.githubusercontent.com/129882b0cfe9711ffd9c0ebcd7ec005d0dc74dba614df7a32882ad40d6f31aea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f64616e68756e73616b65722f6c61726176656c2d7370617469616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/danhunsaker/laravel-spatial)[![](https://camo.githubusercontent.com/b6ee8182ea8025e255e5b99b1bde0def89c2bf07cb4cd501c94e7e78d0b31347/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f64616e68756e73616b65722f6c61726176656c2d7370617469616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/danhunsaker/laravel-spatial)[![](https://camo.githubusercontent.com/274099c02556354884ae30e0ff97bc8b3fc7589dca82a1d3966fa79ffd860870/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64616e68756e73616b65722f6c61726176656c2d7370617469616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/danhunsaker/laravel-spatial)[![](https://camo.githubusercontent.com/ca220f5e238329491b1c2e42a79509da5a179bf3b47c440663d545218c0fa5ae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64616e68756e73616b65722f6c61726176656c2d7370617469616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/danhunsaker/laravel-spatial)

[![](https://camo.githubusercontent.com/5256b6b215b0eb110290b74ebb3dd91b26060a62bbc036f0202b72af2533e2de/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f64616e68756e73616b65722f6c61726176656c2d7370617469616c2e7376673f7374796c653d666c61742d737175617265)](https://github.com/danhunsaker/laravel-spatial)[![](https://camo.githubusercontent.com/cefa39b56d46f412a11c019497ccd72007ad56f2607f5f95887fee52369aee4d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f64616e68756e73616b65722f6c61726176656c2d7370617469616c2e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/danhunsaker/laravel-spatial)[![](https://camo.githubusercontent.com/3efdfd2a7178c14fb96568fb2b0f4c1b3e33020e8289220bf86e63a2c1396369/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f64616e68756e73616b65722f6c61726176656c2d7370617469616c2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/danhunsaker/laravel-spatial/)

This package is fully undocumented and unstable, and is a combination of the two great packages:

- [Laravel PostGIS extension](https://github.com/njbarrett/laravel-postgis)
- [Laravel MySQL spatial extension](https://github.com/grimzy/laravel-mysql-spatial)

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

[](#installation)

Installation made super-easy with [composer](https://getcomposer.org):

```
composer require danhunsaker/laravel-spatial
```

Requirements
------------

[](#requirements)

Works with [PostgreSQL](https://www.postgresql.org) installed [PostGIS](http://postgis.net) extension and [MySQL](http://mysql.com) at least version 5.6.

If you try using it on a shared host which is not fulfilling those requirements, change your provider.

Usage
-----

[](#usage)

### Migrations

[](#migrations)

Add spatial fields to your migrations the same way you would any others:

```
    $table->point('point_column');
    $table->linestring('line_string_column');
    $table->polygon('polygon_column');
    $table->geometry('geometry_column');

    $table->multipoint('multi_point_column');
    $table->multilinestring('multi_line_string_column');
    $table->multipolygon('multi_polygon_column');
    $table->geometrycollection('geometry_collection_column');
```

### Models

[](#models)

Any models that use spatial fields need to use the `LaravelSpatial\Eloquent\SpatialTrait`, and list the spatial fields themselves in the `$spatialFields` property:

```
use LaravelSpatial\Eloquent\SpatialTrait;

// ...

class MyModel extends Model
{
    use SpatialTrait;

    // ...

    protected $spatialFields = ['location'];

    // ...
}
```

### Values

[](#values)

We use the [GeoJson PHP Library](http://jmikola.github.io/geojson/) for describing spatial fields as GeoJSON object, e.g.:

```
use GeoJSON\Geometry\Point;

// ...

$eloquent = new MyModel();
$eloquent->location = new Point([49.7, 6.9]);

// ...

$eloquent->save();
```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

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

Total

5

Last Release

2161d ago

Major Versions

v0.1.0 → v1.0.02020-02-05

v0.1.x-dev → v1.0.12020-07-30

PHP version history (2 changes)v0.1.0PHP ^5.6.4|^7.0

v1.0.0PHP ^7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1534396?v=4)[Hennik Hunsaker](/maintainers/danhunsaker)[@danhunsaker](https://github.com/danhunsaker)

---

Top Contributors

[![danhunsaker](https://avatars.githubusercontent.com/u/1534396?v=4)](https://github.com/danhunsaker "danhunsaker (7 commits)")[![garret-gunter](https://avatars.githubusercontent.com/u/8146238?v=4)](https://github.com/garret-gunter "garret-gunter (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[flow-php/doctrine-dbal-bulk

Bulk inserts and updates for Doctrine DBAL

14361.1k3](/packages/flow-php-doctrine-dbal-bulk)[laravel-liberu/laravel-gedcom

A package that converts gedcom files to Eloquent models

782.5k1](/packages/laravel-liberu-laravel-gedcom)

PHPackages © 2026

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