dimanche 29 janvier 2017

Perform query on a calculated column using Laravel

I want to perform the following SQL statement in PHP using Laravel's Eloquent model:

SELECT *, (3959 * acos(cos(radians(37)) * cos(radians(lat)) * cos(radians(lng) - radians(-122)) + sin(radians(37)) * sin(radians(lat )))) AS distance
FROM example_retailers
HAVING distance < 1000
ORDER BY distance
OFFSET 4
LIMIT 3;

My biggest issue with the above statement is how to add a calculated column using Laravel's Eloquent Model.

This is what I have so far:

ExampleRetailer::
    // TODO: add calculated row
    where('distance', '<', 100)
    ->orderBy('distance')
    ->skip(4)
    ->limit(3)
    ->get();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire