Created
December 27, 2017 16:31
-
-
Save imrealashu/8907decf3c944b2a5de3151d4a8194b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function scopeClosestTo($query, $latitude, $longitude, $radius) | |
{ | |
return $query | |
->whereRaw(" | |
ST_DISTANCE_SPHERE( | |
POINT($latitude, $longitude), | |
POINT(lat, lng)) < $radius | |
"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment