我的以下代码是这样的:
$places = DivePlace::selectRaw("*,(st_distance_sphere( POINT(".$lon.",".$lat.") , point(lon, lat))/1000) as distance")
->havingRaw("distance < ".$radius)
->orderBy("distance")
->paginate(10);
没有“haveRaw”一切都很好.
添加后,出现以下错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘distance’ in
‘having clause’ (SQL: select count(*) as aggregate fromdive_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])