Asked by: dhanu
I have this query
select tbl_container.*,
( 6371 * acos( cos( radians(17.7427643) )
* cos( radians( tbl_locations.latitude ) )
* cos( radians( tbl_locations.longitude ) - radians(83.3277787) )
+ sin( radians(17.7427643) )
* sin( radians( tbl_locations.latitude ) ) ) ) AS distance
from tbl_locations,tbl_container
where tbl_container.`status` = 1
and tbl_container.location_id=tbl_locations.id having distance<4 order by distance asc
For this i have two models Containers,Locations
how to write this query to laravel 5 eloquent...
Answers
Answered by: dhanu at 2017-07-11 04:27PM
I did't get any eloquent model query for this so am using query like this
DB::select(DB::raw(' select tbl_container.*,
( 6371 * acos( cos( radians(17.7427643) )
* cos( radians( tbl_locations.latitude ) )
* cos( radians( tbl_locations.longitude ) - radians(83.3277787) )
+ sin( radians(17.7427643) )
* sin( radians( tbl_locations.latitude ) ) ) ) AS distance
from tbl_locations,tbl_container
where tbl_container.`status` = 1
and tbl_container.location_id=tbl_locations.id having distance<4 order by distance asc '));
and using this DB facade for this raw query
use Illuminate\Support\Facades\DB;
No comments:
Post a Comment