Answer the question
In order to leave comments, you need to log in
Laravel. How to combine a query into a model?
There is a model request:
$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();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question