Skip to content

Commit 8351be7

Browse files
committed
Distance scope won't return points that are identical to the comparing point
1 parent 09d246e commit 8351be7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Eloquent/SpatialTrait.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public function getSpatialFields()
7373

7474
public function scopeDistance($query, $distance, $point, $column_name) {
7575
// TODO: check if array, and transform to string delimited by ,
76-
// TODO: remove the objects with a distance of 0?
77-
return $query->whereRaw("st_distance_sphere(`{$column_name}`, POINT({$point->getLng()}, {$point->getLat()})) <= {$distance}");
76+
return $query
77+
->whereRaw("st_distance_sphere(`{$column_name}`, POINT({$point->getLng()}, {$point->getLat()})) <= {$distance}")
78+
->whereRaw("st_distance_sphere(`{$column_name}`, POINT({$point->getLng()}, {$point->getLat()})) != 0");
7879
}
7980
}

0 commit comments

Comments
 (0)