laravel-spatial maintained by mammutgroup
Description
Mysql Geometry extensions for laravel. Aims to make it easy to work with geometries from laravel models
Authors
Last update
2017/01/08 04:36 (dev-master)
License
Downloads
13
Last update
2017/01/08 04:36
License
Require
- geo-io/wkb-parser ^1.0
- illuminate/database ^5.2
- jmikola/geojson ^1.0
- mammutgroup/database ~0.16
- php >=5.5
Last update
2017/01/08 04:36
License
Require
- geo-io/wkb-parser ^1.0
- illuminate/database ^5.2
- jmikola/geojson ^1.0
- mammutgroup/database ~0.16
- php >=5.5
Last update
2017/01/07 14:44
License
Require
- bosnadev/database ~0.16
- geo-io/wkb-parser ^1.0
- illuminate/database ^5.2
- jmikola/geojson ^1.0
- php >=5.5
Last update
2017/01/03 13:09
License
Require
- bosnadev/database ~0.16
- geo-io/wkb-parser ^1.0
- illuminate/database ^5.2
- jmikola/geojson ^1.0
- php >=5.5
Last update
2016/08/17 02:05
License
Require
- bosnadev/database 0.12
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.1.0
- jmikola/geojson ~1.0
- php >=5.5
Last update
2016/07/26 01:54
License
Require
- bosnadev/database 0.12
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.1.0
- jmikola/geojson ~1.0
- php >=5.5
Last update
2016/07/26 01:48
License
Require
- bosnadev/database 0.12
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.1.0
- jmikola/geojson ~1.0
- php >=5.5
Last update
2016/06/15 06:54
License
Require
- bosnadev/database ~0.16
- geo-io/wkb-parser ^1.0
- illuminate/database ^5.2
- jmikola/geojson ^1.0
- php >=5.5
Last update
2016/05/21 08:00
License
Require
- bosnadev/database ~0.16
- geo-io/wkb-parser ^1.0
- illuminate/database ^5.2
- jmikola/geojson ^1.0
- php >=5.5
Last update
2016/01/26 08:39
License
Require
- bosnadev/database ~0.1
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.1.0
- jmikola/geojson ~1.0
- php >=5.5
Last update
2016/01/26 08:33
License
Require
- geo-io/wkb-parser ^1.0
- illuminate/database ^5.2
- jmikola/geojson ^1.0
- phoenixgao/laravel-postgres-extended-schema ^0.14.0
- php >=5.5
Last update
2016/01/04 07:20
License
Require
- bosnadev/database ~0.1
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.1
- jmikola/geojson ~1.0
- php >=5.5
Last update
2015/11/11 08:02
License
Require
- bosnadev/database ~0.1
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.1
- jmikola/geojson ~1.0
- php >=5.5
Last update
2015/09/21 12:21
License
Require
- bosnadev/database ~0.1
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.0
- jmikola/geojson ~1.0
- php >=5.5
Last update
2015/06/10 16:18
License
Require
- bosnadev/database ~0.1
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.0
- jmikola/geojson ~1.0
- php >=5.5
Last update
2015/06/10 11:32
License
Require
- bosnadev/database ~0.1
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.0
- jmikola/geojson ~1.0
- php >=5.5
Last update
2015/05/20 20:47
License
Require
- bosnadev/database ~0.1
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.0
- jmikola/geojson ~1.0
- php >=5.5
Last update
2015/05/08 20:49
License
Require
- bosnadev/database ~0.1
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.0
- jmikola/geojson ~1.0
- php >=5.5
Last update
2015/05/06 12:46
License
Require
- bosnadev/database ~0.1
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.0
- php >=5.5
Last update
2015/04/29 08:08
License
Require
- bosnadev/database ~0.1
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.0
- php >=5.5
Last update
2015/04/17 20:32
License
Require
- bosnadev/database 0.10.*
- geo-io/wkb-parser ~1.0
- illuminate/database ~5.0
- php >=5.5
Last update
2015/04/17 18:04
License
Require
- bosnadev/database 0.10.*
- geo-io/wkb-parser 0.1.*@dev
- illuminate/database ~5.0
- php >=5.5
Last update
2015/04/17 12:49
License
Require
- bosnadev/database 0.10.*
- illuminate/database ~5.0
- php >=5.5
Last update
2015/04/17 11:20
License
Require
- bosnadev/database 0.10.*
- illuminate/database ~5.0
- php >=5.5
Last update
2015/04/15 09:13
License
Require
- bosnadev/database 0.10.*
- illuminate/database ~5.0
- php >=5.5
Last update
2015/04/13 12:57
License
Require
- bosnadev/database 0.10.*
- illuminate/database ~5.0
- php >=5.5
Last update
2015/04/13 10:31
License
Require
- bosnadev/database 0.10.*
- illuminate/database ~5.0
- php >=5.5
Last update
2015/04/13 10:12
License
Require
- bosnadev/database 0.10.*
- illuminate/database ~5.0
- php >=5.5
Last update
2015/03/27 09:24
License
Require
- bosnadev/database 0.10.*
- illuminate/database ~5.0
- php >=5.5
Last update
2015/03/24 13:52
License
Require
- bosnadev/database 0.10.*
- illuminate/database ~5.0
- php >=5.5
Last update
2015/03/24 13:07
License
Require
- bosnadev/database 0.10.*
- illuminate/database ~5.0
- php >=5.5
Last update
2015/03/22 19:36
License
Require
- bosnadev/database 0.10.*
- illuminate/database ~5.0
- php >=5.5
Last update
2015/03/21 00:36
License
Require
- bosnadev/database 0.10.*
- illuminate/database ~5.0
- php >=5.5
comments powered by Disqus
Laravel Mysql Geometry extension
Features
- 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!))
Versions
Use 2.* for Laravel 5.1.*
Use 3.* for Laravel 5.2.*
Installation
composer require phaza/laravel-postgis
Next add the DatabaseServiceProvider to your config/app.php
file.
'Mammutgroup\LaravelPostgis\DatabaseServiceProvider',
That's all.
Usage
First of all, make sure to enable postgis.
CREATE EXTENSION postgis;
To verify that postgis is enabled
SELECT postgis_full_version();
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
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