Skip to content

Commit 9b774d4

Browse files
committed
Merge branch 'mysql-8.0'
# Conflicts: # .travis.yml # src/Eloquent/SpatialTrait.php # start_db.sh
2 parents 673334d + 52055b4 commit 9b774d4

File tree

6 files changed

+40
-43
lines changed

6 files changed

+40
-43
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ php:
77
- '7.1'
88

99
env:
10-
- MYSQL_VERSION=5.6
1110
- MYSQL_VERSION=5.7
1211
- MYSQL_VERSION=8.0
1312

@@ -32,5 +31,3 @@ script: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
3231
after_script:
3332
- php vendor/bin/coveralls -v
3433
- vendor/bin/test-reporter
35-
36-

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Please check the documentation for your MySQL version. MySQL's Extension for Spa
1616
Add the package using composer:
1717

1818
```shell
19-
composer require grimzy/laravel-mysql-spatial
19+
composer require astrogin/laravel-mysql-spatial
2020
```
2121

2222
Register the service provider in `config/app.php`:
@@ -222,4 +222,4 @@ Available geometry classes:
222222

223223
## Credits
224224

225-
Originally inspired from [njbarrett's Laravel postgis package](https://github.com/njbarrett/laravel-postgis).
225+
Originally inspired from [njbarrett's Laravel postgis package](https://github.com/njbarrett/laravel-postgis).

src/Eloquent/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public function update(array $values)
2020

2121
protected function asWKT(GeometryInterface $geometry)
2222
{
23-
return $this->getQuery()->raw("GeomFromText('".$geometry->toWKT()."')");
23+
return $this->getQuery()->raw("ST_GeomFromText('".$geometry->toWKT()."')");
2424
}
2525
}

src/Eloquent/SpatialTrait.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function performInsert(EloquentBuilder $query, array $options = [])
3737
foreach ($this->attributes as $key => $value) {
3838
if ($value instanceof GeometryInterface) {
3939
$this->geometries[$key] = $value; //Preserve the geometry objects prior to the insert
40-
$this->attributes[$key] = $this->getConnection()->raw(sprintf("GeomFromText('%s')", $value->toWKT()));
40+
$this->attributes[$key] = $this->getConnection()->raw(sprintf("ST_GeomFromText('%s')", $value->toWKT()));
4141
}
4242
}
4343

@@ -74,21 +74,21 @@ public function getSpatialFields()
7474

7575
public function scopeDistance($query, $distance, $geometry, $column_name, $exclude_self = false)
7676
{
77-
$query->whereRaw("st_distance(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) <= {$distance}");
77+
$query->whereRaw("st_distance(`{$column_name}`, ST_GeomFromText('{$geometry->toWkt()}')) <= {$distance}");
7878

7979
if ($exclude_self) {
80-
$query->whereRaw("st_distance(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) != 0");
80+
$query->whereRaw("st_distance(`{$column_name}`, ST_GeomFromText('{$geometry->toWkt()}')) != 0");
8181
}
8282

8383
return $query;
8484
}
8585

8686
public function scopeDistanceSphere($query, $distance, $geometry, $column_name, $exclude_self = false)
8787
{
88-
$query->whereRaw("st_distance_sphere(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) <= {$distance}");
88+
$query->whereRaw("st_distance_sphere(`{$column_name}`, ST_GeomFromText('{$geometry->toWkt()}')) <= {$distance}");
8989

9090
if ($exclude_self) {
91-
$query->whereRaw("st_distance_sphere(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) != 0");
91+
$query->whereRaw("st_distance_sphere(`{$column_name}`, ST_GeomFromText('{$geometry->toWkt()}')) != 0");
9292
}
9393

9494
return $query;
@@ -101,7 +101,7 @@ public function scopeDistanceValue($query, $geometry, $column_name)
101101
if (! $columns) {
102102
$query->select('*');
103103
}
104-
$query->selectRaw("st_distance(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) as distance");
104+
$query->selectRaw("st_distance(`{$column_name}`, ST_GeomFromText('{$geometry->toWkt()}')) as distance");
105105
}
106106

107107
public function scopeDistanceSphereValue($query, $geometry, $column_name)
@@ -111,17 +111,17 @@ public function scopeDistanceSphereValue($query, $geometry, $column_name)
111111
if (! $columns) {
112112
$query->select('*');
113113
}
114-
$query->selectRaw("st_distance_sphere(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) as distance");
114+
$query->selectRaw("st_distance_sphere(`{$column_name}`, ST_GeomFromText('{$geometry->toWkt()}')) as distance");
115115
}
116116

117117
public function scopeBounding($query, Geometry $bounds, $column_name)
118118
{
119-
return $query->whereRaw("st_intersects(GeomFromText('{$bounds->toWkt()}'), `{$column_name}`)");
119+
return $query->whereRaw("st_intersects(ST_GeomFromText('{$bounds->toWkt()}'), `{$column_name}`)");
120120
}
121121

122122
public function scopeComparison($query, $geometryColumn, $geometry, $relationship)
123123
{
124-
$query->whereRaw("st_{$relationship}(`{$geometryColumn}`, GeomFromText('{$geometry->toWkt()}'))");
124+
$query->whereRaw("st_{$relationship}(`{$geometryColumn}`, ST_GeomFromText('{$geometry->toWkt()}'))");
125125

126126
return $query;
127127
}

tests/Unit/Eloquent/BuilderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testUpdatePoint()
3636
{
3737
$this->queryBuilder
3838
->shouldReceive('raw')
39-
->with("GeomFromText('POINT(2 1)')")
39+
->with("ST_GeomFromText('POINT(2 1)')")
4040
->once();
4141

4242
$this->queryBuilder
@@ -50,7 +50,7 @@ public function testUpdateLinestring()
5050
{
5151
$this->queryBuilder
5252
->shouldReceive('raw')
53-
->with("GeomFromText('LINESTRING(0 0,1 1,2 2)')")
53+
->with("ST_GeomFromText('LINESTRING(0 0,1 1,2 2)')")
5454
->once();
5555

5656
$this->queryBuilder
@@ -66,7 +66,7 @@ public function testUpdatePolygon()
6666
{
6767
$this->queryBuilder
6868
->shouldReceive('raw')
69-
->with("GeomFromText('POLYGON((0 0,1 0),(1 0,1 1),(1 1,0 0))')")
69+
->with("ST_GeomFromText('POLYGON((0 0,1 0),(1 0,1 1),(1 1,0 0))')")
7070
->once();
7171

7272
$this->queryBuilder

tests/Unit/Eloquent/SpatialTraitTest.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public function testInsertUpdatePointHasCorrectSql()
3636
$this->model->save();
3737

3838
$this->assertStringStartsWith('insert', $this->queries[0]);
39-
$this->assertContains("GeomFromText('POINT(2 1)')", $this->queries[0]);
39+
$this->assertContains("ST_GeomFromText('POINT(2 1)')", $this->queries[0]);
4040
$this->assertTrue($this->model->exists);
4141

4242
$this->model->point = new Point(1, 2);
4343
$this->model->save();
4444

4545
$this->assertStringStartsWith('update', $this->queries[1]);
46-
$this->assertContains("GeomFromText('POINT(2 1)')", $this->queries[1]);
46+
$this->assertContains("ST_GeomFromText('POINT(2 1)')", $this->queries[1]);
4747
}
4848

4949
public function testInsertUpdateLineStringHasCorrectSql()
@@ -57,14 +57,14 @@ public function testInsertUpdateLineStringHasCorrectSql()
5757
$this->model->save();
5858

5959
$this->assertStringStartsWith('insert', $this->queries[0]);
60-
$this->assertContains("GeomFromText('LINESTRING(2 1,3 2)')", $this->queries[0]);
60+
$this->assertContains("ST_GeomFromText('LINESTRING(2 1,3 2)')", $this->queries[0]);
6161
$this->assertTrue($this->model->exists);
6262

6363
$this->model->linestring = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point1, $point2]);
6464
$this->model->save();
6565

6666
$this->assertStringStartsWith('update', $this->queries[1]);
67-
$this->assertContains("GeomFromText('LINESTRING(2 1,3 2)')", $this->queries[1]);
67+
$this->assertContains("ST_GeomFromText('LINESTRING(2 1,3 2)')", $this->queries[1]);
6868
}
6969

7070
public function testInsertUpdatePolygonHasCorrectSql()
@@ -82,13 +82,13 @@ public function testInsertUpdatePolygonHasCorrectSql()
8282
$this->model->save();
8383

8484
$this->assertStringStartsWith('insert', $this->queries[0]);
85-
$this->assertContains("GeomFromText('POLYGON((2 1,3 2),(2 3,1 2))')", $this->queries[0]);
85+
$this->assertContains("ST_GeomFromText('POLYGON((2 1,3 2),(2 3,1 2))')", $this->queries[0]);
8686
$this->assertTrue($this->model->exists);
8787

8888
$this->model->polygon = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]);
8989
$this->model->save();
9090
$this->assertStringStartsWith('update', $this->queries[1]);
91-
$this->assertContains("GeomFromText('POLYGON((2 1,3 2),(2 3,1 2))')", $this->queries[1]);
91+
$this->assertContains("ST_GeomFromText('POLYGON((2 1,3 2),(2 3,1 2))')", $this->queries[1]);
9292
}
9393

9494
public function testInsertUpdateMultiPointHasCorrectSql()
@@ -102,14 +102,14 @@ public function testInsertUpdateMultiPointHasCorrectSql()
102102
$this->model->save();
103103

104104
$this->assertStringStartsWith('insert', $this->queries[0]);
105-
$this->assertContains("GeomFromText('MULTIPOINT((2 1),(3 2))')", $this->queries[0]);
105+
$this->assertContains("ST_GeomFromText('MULTIPOINT((2 1),(3 2))')", $this->queries[0]);
106106
$this->assertTrue($this->model->exists);
107107

108108
$this->model->multipoint = new \Grimzy\LaravelMysqlSpatial\Types\MultiPoint([$point1, $point2]);
109109
$this->model->save();
110110

111111
$this->assertStringStartsWith('update', $this->queries[1]);
112-
$this->assertContains("GeomFromText('MULTIPOINT((2 1),(3 2))')", $this->queries[1]);
112+
$this->assertContains("ST_GeomFromText('MULTIPOINT((2 1),(3 2))')", $this->queries[1]);
113113
}
114114

115115
public function testInsertUpdateMultiLineStringHasCorrectSql()
@@ -127,13 +127,13 @@ public function testInsertUpdateMultiLineStringHasCorrectSql()
127127
$this->model->save();
128128

129129
$this->assertStringStartsWith('insert', $this->queries[0]);
130-
$this->assertContains("GeomFromText('MULTILINESTRING((2 1,3 2),(2 3,1 2))')", $this->queries[0]);
130+
$this->assertContains("ST_GeomFromText('MULTILINESTRING((2 1,3 2),(2 3,1 2))')", $this->queries[0]);
131131
$this->assertTrue($this->model->exists);
132132

133133
$this->model->multilinestring = new \Grimzy\LaravelMysqlSpatial\Types\MultiLineString([$linestring1, $linestring2]);
134134
$this->model->save();
135135
$this->assertStringStartsWith('update', $this->queries[1]);
136-
$this->assertContains("GeomFromText('MULTILINESTRING((2 1,3 2),(2 3,1 2))')", $this->queries[1]);
136+
$this->assertContains("ST_GeomFromText('MULTILINESTRING((2 1,3 2),(2 3,1 2))')", $this->queries[1]);
137137
}
138138

139139
public function testInsertUpdateMultiPolygonHasCorrectSql()
@@ -160,13 +160,13 @@ public function testInsertUpdateMultiPolygonHasCorrectSql()
160160
$this->model->save();
161161

162162
$this->assertStringStartsWith('insert', $this->queries[0]);
163-
$this->assertContains("GeomFromText('MULTIPOLYGON(((2 1,3 2),(2 3,1 2)),((5 4,6 5),(5 6,4 5)))')", $this->queries[0]);
163+
$this->assertContains("ST_GeomFromText('MULTIPOLYGON(((2 1,3 2),(2 3,1 2)),((5 4,6 5),(5 6,4 5)))')", $this->queries[0]);
164164
$this->assertTrue($this->model->exists);
165165

166166
$this->model->multipolygon = new \Grimzy\LaravelMysqlSpatial\Types\MultiPolygon([$polygon1, $polygon2]);
167167
$this->model->save();
168168
$this->assertStringStartsWith('update', $this->queries[1]);
169-
$this->assertContains("GeomFromText('MULTIPOLYGON(((2 1,3 2),(2 3,1 2)),((5 4,6 5),(5 6,4 5)))')", $this->queries[1]);
169+
$this->assertContains("ST_GeomFromText('MULTIPOLYGON(((2 1,3 2),(2 3,1 2)),((5 4,6 5),(5 6,4 5)))')", $this->queries[1]);
170170
}
171171

172172
public function testInsertUpdateGeometryCollectionHasCorrectSql()
@@ -182,13 +182,13 @@ public function testInsertUpdateGeometryCollectionHasCorrectSql()
182182
$this->model->save();
183183

184184
$this->assertStringStartsWith('insert', $this->queries[0]);
185-
$this->assertContains("GeomFromText('GEOMETRYCOLLECTION(POINT(2 1),LINESTRING(3 2,3 3))')", $this->queries[0]);
185+
$this->assertContains("ST_GeomFromText('GEOMETRYCOLLECTION(POINT(2 1),LINESTRING(3 2,3 3))')", $this->queries[0]);
186186
$this->assertTrue($this->model->exists);
187187

188188
$this->model->geometrycollection = new \Grimzy\LaravelMysqlSpatial\Types\GeometryCollection([$point1, $linestring1]);
189189
$this->model->save();
190190
$this->assertStringStartsWith('update', $this->queries[1]);
191-
$this->assertContains("GeomFromText('GEOMETRYCOLLECTION(POINT(2 1),LINESTRING(3 2,3 3))')", $this->queries[1]);
191+
$this->assertContains("ST_GeomFromText('GEOMETRYCOLLECTION(POINT(2 1),LINESTRING(3 2,3 3))')", $this->queries[1]);
192192
}
193193

194194
public function testScopeDistance()
@@ -199,7 +199,7 @@ public function testScopeDistance()
199199
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
200200
$q = $query->getQuery();
201201
$this->assertNotEmpty($q->wheres);
202-
$this->assertContains("st_distance(`point`, GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
202+
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
203203
}
204204

205205
public function testScopeDistanceExcludingSelf()
@@ -210,8 +210,8 @@ public function testScopeDistanceExcludingSelf()
210210
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
211211
$q = $query->getQuery();
212212
$this->assertNotEmpty($q->wheres);
213-
$this->assertContains("st_distance(`point`, GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
214-
$this->assertContains("st_distance(`point`, GeomFromText('POINT(2 1)')) != 0", $q->wheres[1]['sql']);
213+
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
214+
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) != 0", $q->wheres[1]['sql']);
215215
}
216216

217217
public function testScopeDistanceSphere()
@@ -222,7 +222,7 @@ public function testScopeDistanceSphere()
222222
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
223223
$q = $query->getQuery();
224224
$this->assertNotEmpty($q->wheres);
225-
$this->assertContains("st_distance_sphere(`point`, GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
225+
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
226226
}
227227

228228
public function testScopeDistanceSphereExcludingSelf()
@@ -233,8 +233,8 @@ public function testScopeDistanceSphereExcludingSelf()
233233
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
234234
$q = $query->getQuery();
235235
$this->assertNotEmpty($q->wheres);
236-
$this->assertContains("st_distance_sphere(`point`, GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
237-
$this->assertContains("st_distance_sphere(`point`, GeomFromText('POINT(2 1)')) != 0", $q->wheres[1]['sql']);
236+
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
237+
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) != 0", $q->wheres[1]['sql']);
238238
}
239239

240240
public function testScopeDistanceValue()
@@ -247,7 +247,7 @@ public function testScopeDistanceValue()
247247
$this->assertNotEmpty($q->columns);
248248
$this->assertContains("*", $q->columns[0]);
249249
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
250-
$this->assertContains("st_distance(`point`, GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
250+
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
251251
}
252252

253253
public function testScopeDistanceValueWithSelect()
@@ -260,7 +260,7 @@ public function testScopeDistanceValueWithSelect()
260260
$this->assertNotEmpty($q->columns);
261261
$this->assertContains("some_column", $q->columns[0]);
262262
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
263-
$this->assertContains("st_distance(`point`, GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
263+
$this->assertContains("st_distance(`point`, ST_GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
264264
}
265265

266266
public function testScopeDistanceSphereValue()
@@ -273,7 +273,7 @@ public function testScopeDistanceSphereValue()
273273
$this->assertNotEmpty($q->columns);
274274
$this->assertContains("*", $q->columns[0]);
275275
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
276-
$this->assertContains("st_distance_sphere(`point`, GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
276+
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
277277
}
278278

279279
public function testScopeDistanceSphereValueWithSelect()
@@ -286,7 +286,7 @@ public function testScopeDistanceSphereValueWithSelect()
286286
$this->assertNotEmpty($q->columns);
287287
$this->assertContains("some_column", $q->columns[0]);
288288
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
289-
$this->assertContains("st_distance_sphere(`point`, GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
289+
$this->assertContains("st_distance_sphere(`point`, ST_GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
290290
}
291291

292292
private function buildTestPolygon(){
@@ -308,7 +308,7 @@ public function testScopeBounding()
308308
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
309309
$q = $query->getQuery();
310310
$this->assertNotEmpty($q->wheres);
311-
$this->assertContains("st_intersects(GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'), `point`)", $q->wheres[0]['sql']);
311+
$this->assertContains("st_intersects(ST_GeomFromText('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))'), `point`)", $q->wheres[0]['sql']);
312312
}
313313

314314
public function testScopeComparison()

0 commit comments

Comments
 (0)