You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+46-33Lines changed: 46 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,8 @@ Please check the documentation for your MySQL version. MySQL's Extension for Spa
15
15
-`1.x.x`: MySQL 5.6 (also supports MySQL 5.5 but not all spatial analysis functions)
16
16
-`2.x.x`: MySQL 5.7 and 8.0
17
17
18
+
This package also works with MariaDB. Please refer to the [MySQL/MariaDB Spatial Support Matrix](https://mariadb.com/kb/en/library/mysqlmariadb-spatial-support-matrix/) for compatibility.
19
+
18
20
[TOC]
19
21
20
22
## Installation
@@ -42,8 +44,6 @@ For Laravel versions before 5.5 or if not using auto-discovery, register the ser
42
44
],
43
45
```
44
46
45
-
46
-
47
47
## Quickstart
48
48
49
49
### Create a migration
@@ -75,6 +75,8 @@ class CreatePlacesTable extends Migration {
75
75
$table->string('name')->unique();
76
76
// Add a Point spatial data field named location
77
77
$table->point('location')->nullable();
78
+
// Add a Polygon spatial data field named area
79
+
$table->polygon('area')->nullable();
78
80
$table->timestamps();
79
81
});
80
82
}
@@ -121,22 +123,40 @@ class Place extends Model
121
123
use SpatialTrait;
122
124
123
125
protected $fillable = [
124
-
'name',
126
+
'name'
125
127
];
126
128
127
129
protected $spatialFields = [
128
130
'location',
131
+
'area'
129
132
];
130
133
}
131
134
```
132
135
133
136
### Saving a model
134
137
135
138
```php
139
+
use Grimzy\LaravelMysqlSpatial\Types\Point;
140
+
use Grimzy\LaravelMysqlSpatial\Types\Polygon;
141
+
136
142
$place1 = new Place();
137
143
$place1->name = 'Empire State Building';
138
-
$place1->location = new Point(40.7484404, -73.9878441);
144
+
145
+
// saving a point
146
+
$place1->location = new Point(40.7484404, -73.9878441); // (lat, lng)
@@ -177,7 +195,7 @@ Note about spatial indexes from the [MySQL documentation](https://dev.mysql.com/
177
195
178
196
> For [`MyISAM`](https://dev.mysql.com/doc/refman/5.7/en/myisam-storage-engine.html) and (as of MySQL 5.7.5) `InnoDB` tables, MySQL can create spatial indexes using syntax similar to that for creating regular indexes, but using the `SPATIAL` keyword. Columns in spatial indexes must be declared `NOT NULL`.
179
197
180
-
Following the example in the [Quickstart](#user-content-create-a-migration); from the command line:
198
+
For example, as a follow up to the [Quickstart](#user-content-create-a-migration); from the command line, generate a new migration:
181
199
182
200
```shell
183
201
php artisan make:migration update_places_table
@@ -231,8 +249,6 @@ class UpdatePlacesTable extends Migration
231
249
}
232
250
```
233
251
234
-
235
-
236
252
## Geometry classes
237
253
238
254
### Available Geometry classes
@@ -247,6 +263,8 @@ class UpdatePlacesTable extends Migration
Check out the [Class diagram](https://user-images.githubusercontent.com/1837678/30788608-a5afd894-a16c-11e7-9a51-0a08b331d4c4.png).
267
+
250
268
### Using Geometry classes
251
269
252
270
In order for your Eloquent Model to handle the Geometry classes, it must use the `Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait` trait and define a `protected` property `$spatialFields` as an array of MySQL Spatial Data Type column names (example in [Quickstart](#user-content-create-a-model)).
@@ -267,7 +285,7 @@ for($polygon as $i => $linestring) {
267
285
268
286
#### Helpers
269
287
270
-
##### From/To Well Kown Text ([WKT](https://dev.mysql.com/doc/refman/5.7/en/gis-data-formats.html#gis-wkt-format))
288
+
##### From/To Well Known Text ([WKT](https://dev.mysql.com/doc/refman/5.7/en/gis-data-formats.html#gis-wkt-format))
Spatial analysis functions are implemented using [Eloquent Local Scopes](https://laravel.com/docs/5.4/eloquent#local-scopes).
@@ -336,8 +351,6 @@ Available scopes:
336
351
337
352
*Note that behavior and availability of MySQL spatial analysis functions differs in each MySQL version (cf. [documentation](https://dev.mysql.com/doc/refman/5.7/en/spatial-function-reference.html)).*
338
353
339
-
340
-
341
354
## Credits
342
355
343
356
Originally inspired from [njbarrett's Laravel postgis package](https://github.com/njbarrett/laravel-postgis).
0 commit comments