@@ -132,8 +132,9 @@ public function scopeDistance($query, $geometryColumn, $geometry, $distance)
132132 {
133133 $ this ->isColumnAllowed ($ geometryColumn );
134134
135- $ query ->whereRaw ("st_distance(` $ geometryColumn`, ST_GeomFromText(?)) <= ? " , [
135+ $ query ->whereRaw ("st_distance(` $ geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) <= ? " , [
136136 $ geometry ->toWkt (),
137+ $ geometry ->getSrid (),
137138 $ distance ,
138139 ]);
139140
@@ -146,8 +147,9 @@ public function scopeDistanceExcludingSelf($query, $geometryColumn, $geometry, $
146147
147148 $ query = $ this ->scopeDistance ($ query , $ geometryColumn , $ geometry , $ distance );
148149
149- $ query ->whereRaw ("st_distance(` $ geometryColumn`, ST_GeomFromText(?)) != 0 " , [
150+ $ query ->whereRaw ("st_distance(` $ geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) != 0 " , [
150151 $ geometry ->toWkt (),
152+ $ geometry ->getSrid (),
151153 ]);
152154
153155 return $ query ;
@@ -163,17 +165,19 @@ public function scopeDistanceValue($query, $geometryColumn, $geometry)
163165 $ query ->select ('* ' );
164166 }
165167
166- $ query ->selectRaw ("st_distance(` $ geometryColumn`, ST_GeomFromText(?)) as distance " , [
168+ $ query ->selectRaw ("st_distance(` $ geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) as distance " , [
167169 $ geometry ->toWkt (),
170+ $ geometry ->getSrid (),
168171 ]);
169172 }
170173
171174 public function scopeDistanceSphere ($ query , $ geometryColumn , $ geometry , $ distance )
172175 {
173176 $ this ->isColumnAllowed ($ geometryColumn );
174177
175- $ query ->whereRaw ("st_distance_sphere(` $ geometryColumn`, ST_GeomFromText(?)) <= ? " , [
178+ $ query ->whereRaw ("st_distance_sphere(` $ geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) <= ? " , [
176179 $ geometry ->toWkt (),
180+ $ geometry ->getSrid (),
177181 $ distance ,
178182 ]);
179183
@@ -186,8 +190,9 @@ public function scopeDistanceSphereExcludingSelf($query, $geometryColumn, $geome
186190
187191 $ query = $ this ->scopeDistanceSphere ($ query , $ geometryColumn , $ geometry , $ distance );
188192
189- $ query ->whereRaw ("st_distance_sphere( $ geometryColumn, ST_GeomFromText(?)) != 0 " , [
193+ $ query ->whereRaw ("st_distance_sphere( $ geometryColumn, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) != 0 " , [
190194 $ geometry ->toWkt (),
195+ $ geometry ->getSrid (),
191196 ]);
192197
193198 return $ query ;
@@ -202,8 +207,9 @@ public function scopeDistanceSphereValue($query, $geometryColumn, $geometry)
202207 if (!$ columns ) {
203208 $ query ->select ('* ' );
204209 }
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 " , [
206211 $ geometry ->toWkt (),
212+ $ geometry ->getSrid (),
207213 ]);
208214 }
209215
@@ -215,8 +221,9 @@ public function scopeComparison($query, $geometryColumn, $geometry, $relationshi
215221 throw new UnknownSpatialRelationFunction ($ relationship );
216222 }
217223
218- $ query ->whereRaw ("st_ {$ relationship }(` $ geometryColumn`, ST_GeomFromText(?)) " , [
224+ $ query ->whereRaw ("st_ {$ relationship }(` $ geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) " , [
219225 $ geometry ->toWkt (),
226+ $ geometry ->getSrid (),
220227 ]);
221228
222229 return $ query ;
@@ -270,8 +277,9 @@ public function scopeOrderBySpatial($query, $geometryColumn, $geometry, $orderFu
270277 throw new UnknownSpatialFunctionException ($ orderFunction );
271278 }
272279
273- $ query ->orderByRaw ("st_ {$ orderFunction }(` $ geometryColumn`, ST_GeomFromText(?)) {$ direction }" , [
280+ $ query ->orderByRaw ("st_ {$ orderFunction }(` $ geometryColumn`, ST_GeomFromText(?, ?, 'axis-order=long-lat' )) {$ direction }" , [
274281 $ geometry ->toWkt (),
282+ $ geometry ->getSrid (),
275283 ]);
276284
277285 return $ query ;
0 commit comments