Skip to content

Commit 6544516

Browse files
author
Adam Hutchison
committed
Adds orderByDistanceFrom method to DB builder
1 parent 23dd3a6 commit 6544516

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/GeoScopeServiceProvider.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ public function boot()
3737
'configOption' => $configOption,
3838
])->orWithinDistanceOf($lat, $long, $distance);
3939
});
40+
41+
Builder::macro('orderByDistanceFrom', function (
42+
float $lat,
43+
float $long,
44+
$orderDirection = 'asc'
45+
) {
46+
return app(DatabaseBuilderBuilderScope::class, [
47+
'query' => $this,
48+
])->orderByDistanceFrom($lat, $long, $orderDirection);
49+
});
4050
}
4151

4252
public function register()

0 commit comments

Comments
 (0)