Skip to content

Commit

Permalink
Adds orderByDistanceFrom method to DB builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Hutchison committed Feb 29, 2020
1 parent 23dd3a6 commit 6544516
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/GeoScopeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ public function boot()
'configOption' => $configOption,
])->orWithinDistanceOf($lat, $long, $distance);
});

Builder::macro('orderByDistanceFrom', function (
float $lat,
float $long,
$orderDirection = 'asc'
) {
return app(DatabaseBuilderBuilderScope::class, [
'query' => $this,
])->orderByDistanceFrom($lat, $long, $orderDirection);
});
}

public function register()
Expand Down

0 comments on commit 6544516

Please sign in to comment.