Skip to content

Commit 67427a0

Browse files
committed
Added local scope to filter with a bounding box
1 parent 8351be7 commit 67427a0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Eloquent/SpatialTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,8 @@ public function scopeDistance($query, $distance, $point, $column_name) {
7777
->whereRaw("st_distance_sphere(`{$column_name}`, POINT({$point->getLng()}, {$point->getLat()})) <= {$distance}")
7878
->whereRaw("st_distance_sphere(`{$column_name}`, POINT({$point->getLng()}, {$point->getLat()})) != 0");
7979
}
80+
81+
public function scopeBounding($query, Geometry $bounds, $column_name) {
82+
return $query->whereRaw("MBRIntersects(ST_GeomFromText('{$bounds->toWkt()}'), `{$column_name}`)");
83+
}
8084
}

0 commit comments

Comments
 (0)