- Work with geometry classes instead of arrays. (
$myModel->myPoint = new Point(1,2)
) - Adds helpers in migrations. (
$table->polygon('myColumn')
)
- Geometry functions on the geometry classes (contains(), equals(), distance(), etc… (HELP!))
First of all, enable postgis (See note further down)
use Illuminate\Database\Migrations\Migration;
use Phaza\LaravelPostgis\Schema\Blueprint;
class CreateTestsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tests', function(Blueprint $table)
{
$table->increments('id');
$table->polygon('myPolygon');
$table->point('myPoint');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('tests');
}
}
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 associative array called $postgisFields
which defines
what attributes/columns on your model are to be considered geometry objects.
class TestModel extends Model {
use PostgisTrait;
protected $postgisFields = [
'point' => Point::class
];
}
$testModel = new TestModel();
$testModel->point = new Point(1,2);
$testModel->save();
$testModel2 = TestModel::first();
$testModel2->point instanceof Point // true
Available geometry classes:
- Point
- MultiPoint
- LineString
- MultiLineString
- Polygon
- MultiPolygon
- GeometryCollection
A method called enablePostgis() (and disablePostgis()) is included in the Blueprint object. They work on newer postgres installations, but I recommend enabling postgis manually for now.