From 6f06047a1608e7ab74e75303be699b112af0e667 Mon Sep 17 00:00:00 2001 From: Dan Hunsaker Date: Sun, 23 Dec 2018 13:36:09 -0700 Subject: [PATCH 1/2] cleanup extraneous files --- .gitignore | 15 +----- .idea/laravel-spatial.iml | 107 -------------------------------------- .idea/modules.xml | 8 --- .idea/php.xml | 51 ------------------ .idea/vagrant.xml | 7 --- 5 files changed, 1 insertion(+), 187 deletions(-) delete mode 100644 .idea/laravel-spatial.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/php.xml delete mode 100644 .idea/vagrant.xml diff --git a/.gitignore b/.gitignore index a5bf6a6..ac4bf32 100755 --- a/.gitignore +++ b/.gitignore @@ -1,20 +1,7 @@ /bootstrap/compiled.php /vendor /node_modules -.idea/workspace.xml -.idea/tasks.xml -.idea/dictionaries -.idea/vcs.xml -.idea/jsLibraryMappings.xml -.idea/dataSources.ids -.idea/dataSources.xml -.idea/dataSources.local.xml -.idea/sqlDataSources.xml -.idea/dynamic.xml -.idea/uiDesigner.xml -.idea/gradle.xml -.idea/libraries -.idea/mongoSettings.xml +.idea/ *.iws /out/ .idea_modules/ diff --git a/.idea/laravel-spatial.iml b/.idea/laravel-spatial.iml deleted file mode 100644 index 07562a5..0000000 --- a/.idea/laravel-spatial.iml +++ /dev/null @@ -1,107 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 750254a..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml deleted file mode 100644 index 821a545..0000000 --- a/.idea/php.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vagrant.xml b/.idea/vagrant.xml deleted file mode 100644 index c334934..0000000 --- a/.idea/vagrant.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file From fe9895859af948b504732850f347c6cc6a250164 Mon Sep 17 00:00:00 2001 From: Dan Hunsaker Date: Fri, 28 Dec 2018 11:52:33 -0700 Subject: [PATCH 2/2] Add usage instructions to the README Along with a tiny bit of cleanup of the file's formatting. --- README.md | 62 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6e17167..156ff86 100755 --- a/README.md +++ b/README.md @@ -1,13 +1,15 @@ # Laravel Spatial extension This package is fully untested, undocumented and unstable and is a combination of the two great packages: -- [Laravel PostGIS extension](https://github.com/njbarrett/laravel-postgis) -- [Laravel MySQL spatial extension](https://github.com/grimzy/laravel-mysql-spatial) + +- [Laravel PostGIS extension](https://github.com/njbarrett/laravel-postgis) +- [Laravel MySQL spatial extension](https://github.com/grimzy/laravel-mysql-spatial) ## Installation Installation made super-easy with [composer](https://getcomposer.org): -``` + +```bash composer require apptimists/laravel-spatial ``` @@ -21,16 +23,56 @@ If you try using it on a shared host which is not fulfilling those requirements, ## Usage -We use the [GeoJson PHP Library](http://jmikola.github.io/geojson/) for describing spatial fields as GeoJSON object, e.g.: +### Migrations + +Add spatial fields to your migrations the same way you would any others: + +```php + $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: + +```php +use LaravelSpatial\Eloquent\SpatialTrait; + +// ... + +class MyModel extends Model +{ + use SpatialTrait; + + // ... + + protected $spatialFields = ['location']; + + // ... +} ``` + +### Values + +We use the [GeoJson PHP Library](http://jmikola.github.io/geojson/) for describing spatial fields as GeoJSON object, e.g.: + +```php use GeoJSON\Geometry\Point; - -... - + +// ... + $eloquent = new MyModel(); $eloquent->location = new Point([49.7, 6.9]); - -... - + +// ... + $eloquent->save(); ```