我正在尝试找到问题的解决方案,但找不到任何有用的东西。我需要获取此查询创建的“距离”变量以及所有其他数据(用户,userData,商品等)。对于我拍摄的每张唱片,我需要在视图中打印“km”的距离。
以下是代码:
if(property_exists($params, "lat") && property_exists($params, "lng")) {
if(null == $params->lat || null == $params->lng) {
//don't use coordinates
} else {
$radius = $this->coordMaxRadius;
$query->whereHas("userData", function($q) use ($params, $radius) {
$q->selectRaw( \DB::raw("
ROUND( 6371 * acos( cos( radians($params->lat) )
* cos( radians( lat ) )
* cos( radians( lng ) - radians($params->lng) )
+ sin( radians($params->lat) )
* sin( radians( lat ) ) ) ) AS distance "));
$q->having("distance", "<", $radius)->orderBy("distance");
});
}
}
/***** later in the code *****/
$query->with("timeSlots.days", "timeSlots.time", "userData",
"university", "faculty", "user", 'userData.feedbacks');
答案 0 :(得分:0)
我也在几周之前处理同样的问题。我有解决方案,但我知道完全正确与否
#If the list color has at least one color in it (E.g)color = ['blue','white','maladroit']
print('Nothing to see here')
#If the list only consists of elements that aren't colors
#(E.g)color = ['hurley','maladroit']
print("I don't see colors.... I actually legit don't...")