gpt4 book ai didi

php - Laravel 5 Eloquent 地查询半正矢公式

转载 作者:行者123 更新时间:2023-11-29 18:39:39 24 4
gpt4 key购买 nike

我有这个查询

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

为此,我有两个模型容器,位置

如何将此查询写入 laravel 5 eloquent...

最佳答案

我没有得到任何 Eloquent 模型查询所以我使用这样的查询

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 '));

并使用此数据库外观来执行此原始查询

use Illuminate\Support\Facades\DB;

关于php - Laravel 5 Eloquent 地查询半正矢公式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45032111/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com