@@ -132,8 +132,9 @@ public function scopeDistance($query, $geometryColumn, $geometry, $distance)
132
132
{
133
133
$ this ->isColumnAllowed ($ geometryColumn );
134
134
135
- $ query ->whereRaw ("st_distance(` $ geometryColumn`, ST_GeomFromText(?)) <= ? " , [
135
+ $ query ->whereRaw ("st_distance(` $ geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) <= ? " , [
136
136
$ geometry ->toWkt (),
137
+ $ geometry ->getSrid (),
137
138
$ distance ,
138
139
]);
139
140
@@ -146,8 +147,9 @@ public function scopeDistanceExcludingSelf($query, $geometryColumn, $geometry, $
146
147
147
148
$ query = $ this ->scopeDistance ($ query , $ geometryColumn , $ geometry , $ distance );
148
149
149
- $ query ->whereRaw ("st_distance(` $ geometryColumn`, ST_GeomFromText(?)) != 0 " , [
150
+ $ query ->whereRaw ("st_distance(` $ geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) != 0 " , [
150
151
$ geometry ->toWkt (),
152
+ $ geometry ->getSrid (),
151
153
]);
152
154
153
155
return $ query ;
@@ -163,17 +165,19 @@ public function scopeDistanceValue($query, $geometryColumn, $geometry)
163
165
$ query ->select ('* ' );
164
166
}
165
167
166
- $ query ->selectRaw ("st_distance(` $ geometryColumn`, ST_GeomFromText(?)) as distance " , [
168
+ $ query ->selectRaw ("st_distance(` $ geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) as distance " , [
167
169
$ geometry ->toWkt (),
170
+ $ geometry ->getSrid (),
168
171
]);
169
172
}
170
173
171
174
public function scopeDistanceSphere ($ query , $ geometryColumn , $ geometry , $ distance )
172
175
{
173
176
$ this ->isColumnAllowed ($ geometryColumn );
174
177
175
- $ query ->whereRaw ("st_distance_sphere(` $ geometryColumn`, ST_GeomFromText(?)) <= ? " , [
178
+ $ query ->whereRaw ("st_distance_sphere(` $ geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) <= ? " , [
176
179
$ geometry ->toWkt (),
180
+ $ geometry ->getSrid (),
177
181
$ distance ,
178
182
]);
179
183
@@ -186,8 +190,9 @@ public function scopeDistanceSphereExcludingSelf($query, $geometryColumn, $geome
186
190
187
191
$ query = $ this ->scopeDistanceSphere ($ query , $ geometryColumn , $ geometry , $ distance );
188
192
189
- $ query ->whereRaw ("st_distance_sphere( $ geometryColumn, ST_GeomFromText(?)) != 0 " , [
193
+ $ query ->whereRaw ("st_distance_sphere( $ geometryColumn, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) != 0 " , [
190
194
$ geometry ->toWkt (),
195
+ $ geometry ->getSrid (),
191
196
]);
192
197
193
198
return $ query ;
@@ -202,8 +207,9 @@ public function scopeDistanceSphereValue($query, $geometryColumn, $geometry)
202
207
if (!$ columns ) {
203
208
$ query ->select ('* ' );
204
209
}
205
- $ query ->selectRaw ("st_distance_sphere(` $ geometryColumn`, ST_GeomFromText(?)) as distance " , [
210
+ $ query ->selectRaw ("st_distance_sphere(` $ geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) as distance " , [
206
211
$ geometry ->toWkt (),
212
+ $ geometry ->getSrid (),
207
213
]);
208
214
}
209
215
@@ -215,8 +221,9 @@ public function scopeComparison($query, $geometryColumn, $geometry, $relationshi
215
221
throw new UnknownSpatialRelationFunction ($ relationship );
216
222
}
217
223
218
- $ query ->whereRaw ("st_ {$ relationship }(` $ geometryColumn`, ST_GeomFromText(?)) " , [
224
+ $ query ->whereRaw ("st_ {$ relationship }(` $ geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) " , [
219
225
$ geometry ->toWkt (),
226
+ $ geometry ->getSrid (),
220
227
]);
221
228
222
229
return $ query ;
@@ -270,8 +277,9 @@ public function scopeOrderBySpatial($query, $geometryColumn, $geometry, $orderFu
270
277
throw new UnknownSpatialFunctionException ($ orderFunction );
271
278
}
272
279
273
- $ query ->orderByRaw ("st_ {$ orderFunction }(` $ geometryColumn`, ST_GeomFromText(?)) {$ direction }" , [
280
+ $ query ->orderByRaw ("st_ {$ orderFunction }(` $ geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) {$ direction }" , [
274
281
$ geometry ->toWkt (),
282
+ $ geometry ->getSrid (),
275
283
]);
276
284
277
285
return $ query ;
0 commit comments