I have the following sql query that I need to convert into a Eloquent query I have the lat and lng fields in the user table. After some searching I found there is a $user->whereRaw() method on eloquent but that is as far as I got. I need to select all users within the 25 mile radius.
SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;
It should work as $user->whereRaw() I think at least that is all I was able to find.
I need to mention that I am doing many queries before and after this, such as
$user->where()
$user->where()
Then this query needs to run
$user->where()
and finally
$user->get()