I use laravel 5.4
My sql query is like this :
'SELECT * FROM
(SELECT id, (' . $circle_radius . ' * acos(cos(radians(' . $lat . ')) * cos(radians(geo_lat)) *
cos(radians(geo_lon) - radians(' . $lng . ')) +
sin(radians(' . $lat . ')) * sin(radians(geo_lat))))
AS distance
FROM locations) AS distances
WHERE distance < ' . $max_distance . '
ORDER BY distance;
'
I want to change it to be laravel eloquent
I use this
DB::select(
'SELECT * FROM
(SELECT id, (' . $circle_radius . ' * acos(cos(radians(' . $lat . ')) * cos(radians(geo_lat)) *
cos(radians(geo_lon) - radians(' . $lng . ')) +
sin(radians(' . $lat . ')) * sin(radians(geo_lat))))
AS distance
FROM locations) AS distances
WHERE distance < ' . $max_distance . '
ORDER BY distance;
');
it work but I need to use model how can I use Location model.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2xV1bro
via IFTTT
Aucun commentaire:
Enregistrer un commentaire