@@ -72,24 +72,18 @@ public function getSpatialFields()
7272 }
7373 }
7474
75- public function scopeDistance ($ query , $ geometryColumn , $ geometry , $ distance, $ exclude_self = false )
75+ public function scopeDistance ($ query , $ geometryColumn , $ geometry , $ distance )
7676 {
7777 $ query ->whereRaw ("st_distance(` {$ geometryColumn }`, ST_GeomFromText(' {$ geometry ->toWkt ()}')) <= {$ distance }" );
7878
79- if ($ exclude_self ) {
80- $ query ->whereRaw ("st_distance(` {$ geometryColumn }`, ST_GeomFromText(' {$ geometry ->toWkt ()}')) != 0 " );
81- }
82-
8379 return $ query ;
8480 }
8581
86- public function scopeDistanceSphere ($ query , $ geometryColumn , $ geometry , $ distance, $ exclude_self = false )
82+ public function scopeDistanceExcludingSelf ($ query , $ geometryColumn , $ geometry , $ distance )
8783 {
88- $ query-> whereRaw ( " st_distance_sphere(` { $ geometryColumn} `, ST_GeomFromText(' { $ geometry-> toWkt ()} ')) <= { $ distance}" );
84+ $ query = $ this -> scopeDistance ( $ query , $ geometryColumn, $ geometry, $ distance );
8985
90- if ($ exclude_self ) {
91- $ query ->whereRaw ("st_distance_sphere(` {$ geometryColumn }`, ST_GeomFromText(' {$ geometry ->toWkt ()}')) != 0 " );
92- }
86+ $ query ->whereRaw ("st_distance(` {$ geometryColumn }`, ST_GeomFromText(' {$ geometry ->toWkt ()}')) != 0 " );
9387
9488 return $ query ;
9589 }
@@ -104,6 +98,22 @@ public function scopeDistanceValue($query, $geometryColumn, $geometry)
10498 $ query ->selectRaw ("st_distance(` {$ geometryColumn }`, ST_GeomFromText(' {$ geometry ->toWkt ()}')) as distance " );
10599 }
106100
101+ public function scopeDistanceSphere ($ query , $ geometryColumn , $ geometry , $ distance )
102+ {
103+ $ query ->whereRaw ("st_distance_sphere(` {$ geometryColumn }`, ST_GeomFromText(' {$ geometry ->toWkt ()}')) <= {$ distance }" );
104+
105+ return $ query ;
106+ }
107+
108+ public function scopeDistanceSphereExcludingSelf ($ query , $ geometryColumn , $ geometry , $ distance )
109+ {
110+ $ query = $ this ->scopeDistanceSphere ($ query , $ geometryColumn , $ geometry , $ distance );
111+
112+ $ query ->whereRaw ("st_distance_sphere(` {$ geometryColumn }`, ST_GeomFromText(' {$ geometry ->toWkt ()}')) != 0 " );
113+
114+ return $ query ;
115+ }
116+
107117 public function scopeDistanceSphereValue ($ query , $ geometryColumn , $ geometry )
108118 {
109119 $ columns = $ query ->getQuery ()->columns ;
0 commit comments