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

3.1.3 2017-01-08 04:36 UTC


Build Status Code Climate Coverage Status


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

Future plans

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


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


composer require phaza/laravel-postgis 

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


That's all.


First of all, make sure to enable postgis.


To verify that postgis is enabled

SELECT postgis_full_version();


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)

     * Reverse the migrations.
     * @return void
    public function down()


Available blueprint geometries:

  • point
  • multipoint
  • linestring
  • multilinestring
  • polygon
  • multipolygon
  • geometrycollection

other methods:

  • enablePostgis
  • disablePostgis


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 = [

    protected $postgisFields = [


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

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

Available geometry classes:

  • Point
  • MultiPoint
  • LineString
  • MultiLineString
  • Polygon
  • MultiPolygon
  • GeometryCollection