$lat = (float) 55;
$lng = (float) 37;
$city = $lat.','$lng
$locations = Locality::where('point', $city)
->with('rating_results')
->firstOrFail();
$nearest = \DB::table('localities')->select(\DB::raw("*,
(6371 * ACOS(COS(RADIANS($lat))
* COS(RADIANS(latitude))
* COS(RADIANS($lng) - RADIANS(longitude))
+ SIN(RADIANS($lat))
* SIN(RADIANS(latitude)))) AS distance")
)->orderBy('distance', 'asc')->take(20)->get();
$lat = (float) 55;
$lng = (float) 37;
$city = $lat.','$lng;
$nearest = \DB::table('localities')
->where('point', $city)
// join поправь под структуру таблицы.
->join('rating_results','localities.id','rating_results.local_id')
->select(\DB::raw("*,
(6371 * ACOS(COS(RADIANS($lat))
* COS(RADIANS(latitude))
* COS(RADIANS($lng) - RADIANS(longitude))
+ SIN(RADIANS($lat))
* SIN(RADIANS(latitude)))) AS distance")
)
->orderBy('distance', 'asc')->take(20)->get();