Level 9
Got it:
Profiles Controller
public function index(User $user, Request $request)
{
//$location = GeoIP::getLocation($request->ip());
$authUser = Auth::user();
$users = $user->scopeIsWithinMaxDistance($authUser->lat, $authUser->lng, 5 )->all();//paginate(20);
view('profiles.index', compact('users'));
}
User Model
public function scopeIsWithinMaxDistance($query, $lat, $lng, $radius = 25) {
$haversine = "(6371 * acos(cos(radians($lat))
* cos(radians(user.lat))
* cos(radians(user.lng)
- radians($lng))
+ sin(radians($lat))
* sin(radians(user.lat))))";
return $query
->select('id') //pick the columns you want here.
->selectRaw("{$haversine} AS distance")
->whereRaw("{$haversine} < ?", [$radius]);
}
I now have the joy of getting a totally separate error. Which probably deserves its own thread because I can't find it anywhere with a google search.