Convert SQL query to Eloquent Laravel based on two parameters
I have a sql query:
SELECT lat, lng, SQRT( POW(69.1 * (lat - $lat), 2) + POW(69.1 * ($lng - lng) * COS(lat / 57.3), 2)) AS distance FROM locations HAVING distance < 25 ORDER BY distance;
Now I want to convert it to Eloquent But here is the problem
TIll now, I have queried my tables based on one parameter
Venue::where('lat',">",12.133) But Now I wanna kinda run a procedure on my table And I don't know How to accomplish this kind of queries.
How Do yo do that?
I really doubt you can get that query using Eloquent... But you can use query builder and
Locations::select(DB::raw(" lat,lng, SQRT( POW(69.1 * (lat - $lat), 2) + POW(69.1 * ($lng - lng) * COS(lat / 57.3), 2)) AS distance")) ->havingRaw('distance < 25') ->orderBy('distance')
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?