Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

laravel-postgis

> 编程语言
Open source

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

381 stars0 likes2 views
WebsiteGitHub

About

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

Laravel Wrapper for PostgreSQL's Geo-Extension Postgis

DEPRECATED

Consider using: https://github.com/clickbar/laravel-magellan

Features

  • Work with geometry classes instead of arrays.
php
$model->myPoint = new Point(1,2);  //lat, long
  • Adds helpers in migrations.
php
$table->polygon('myColumn');

Warning

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

Replace all your references to the new namespace:

MStaack\LaravelPostgis

Thanks to :

  • https://github.com/njbarrett
  • https://github.com/phaza
  • https://github.com/mirzap

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

Installation

  • Use 3.* for Laravel 5
bash
composer require "mstaack/laravel-postgis:3.*"
  • Use 5.* for Laravel 6/7/8/9
bash
composer require mstaack/laravel-postgis

For laravel >=5.5 that's all. This package supports Laravel new Package Discovery.

If you are using Laravel 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');
}

}

…

PHP 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

## Publishing config
A configuration file exists for overriding default values. To add to your project, run:

```sh
php artisan vendor:publish --provider="MStaack\LaravelPostgis\DatabaseServiceProvider" --tag="postgis"

Coordinate precision

The precision of stored/displayed coordinated can be customised in the config.

php
# config/postgis.php
return [
    ...
    'precision' => 6,
];

See http://wiki.gis.com/wiki/index.php/Decimal_degrees#Accuracy for more information

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言