New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

danhunsaker/laravel-spatial

Spatial data types extension for Laravel.
8,962 1
Install
composer require danhunsaker/laravel-spatial
Latest Version:v1.0.1
PHP:^7.2
Laravel:5 · 6 · 7
License:MIT
Last Updated:Feb 15, 2022
Links: GitHub  ·  Packagist
Maintainer: danhunsaker

Laravel Spatial extension

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

Installation

Installation made super-easy with composer:

composer require danhunsaker/laravel-spatial

Requirements

Works with PostgreSQL installed PostGIS extension and MySQL at least version 5.6.

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

Usage

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

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

We use the GeoJson PHP Library 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();

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

648,266,899 9,701
laravel/framework

The Laravel Framework.

604,216,237 34,982
laravel/tinker

Powerful REPL for the Laravel framework.

512,508,631 7,443
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

429,221,767 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

403,217,078 4,664

Version History

Version Released PHP Laravel License
v1.0.1 ^7.2 ^5.7 || ^6.0 || ^7.0 MIT
v1.0.0 ^7.2 ^5.7 || ^6.0 MIT
v0.1.1 ^7.2 ~5.5.0 || ~5.6.0 MIT
v0.1.0 ^5.6.4|^7.0 ^5.3 MIT