mercredi 26 septembre 2018

How can I make select in select on laravel eloquent using model?

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.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire