laravel具有:找不到列 [英] laravel having: Column not found
本文介绍了laravel具有:找不到列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的以下代码是这样的:
my following code is like this:
$places = DivePlace::selectRaw("*,(st_distance_sphere( POINT(".$lon.",".$lat.") , point(lon, lat))/1000) as distance")
->havingRaw("distance < ".$radius)
->orderBy("distance")
->paginate(10);
没有"havingRaw",一切都很好. 添加后,出现以下错误:
without the "havingRaw" everything is good. After adding it, the following error came up:
SQLSTATE [42S22]:找不到列:1054中的未知列'距离' '具有子句'(SQL:从
dive_places
中选择count(*)作为聚合 距离< 300)
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in 'having clause' (SQL: select count(*) as aggregate from
dive_places
having distance < 300)
有解决方案吗?
推荐答案
->where(DB::raw("(ST_Distance_Sphere(POINT(".$lon.",".$lat."), POINT(lon,lat))/1000)"), '<', 200)
而不是->havingRaw("(st_distance_sphere( POINT(?, ?) , point(lon, lat))/1000) < ?", [$lon, $lat, $radius])
这篇关于laravel具有:找不到列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文