代码:
if ($request->going){
if($request->lattitude && $request->longitude){
$CurrentIplat = $request->lattitude;
$CurrentIplon = $request->longitude;
$ads1 = DB::table('ads')
->leftJoin('categories', 'ads.category_id', '=', 'categories.id')
->select(
'ads.*','categories.category_name',
DB::raw("( 6371 * acos( cos( radians('{$CurrentIplat}') ) * cos( radians( ads.Latitude ) ) * cos( radians( ads.Longtitute ) - radians({$CurrentIplon}) ) + sin( radians({$CurrentIplat}) ) * sin( radians( ads.Latitude ) ) ) ) AS distance")
)
->where('ads.domain',$this->domain)
->groupBy('ads.id')
->orderBy('distance')
->having('distance','<','500')
->get();
}
}
提供适当的输出。
使用 paginate() 时
if ($request->going){
if($request->lattitude && $request->longitude){
$CurrentIplat = $request->lattitude;
$CurrentIplon = $request->longitude;
$ads1 = DB::table('ads')
->leftJoin('categories', 'ads.category_id', '=', 'categories.id')
->select(
'ads.*','categories.category_name',
DB::raw("( 6371 * acos( cos( radians('{$CurrentIplat}') ) * cos( radians( ads.Latitude ) ) * cos( radians( ads.Longtitute ) - radians({$CurrentIplon}) ) + sin( radians({$CurrentIplat}) ) * sin( radians( ads.Latitude ) ) ) ) AS distance")
)
->where('ads.domain',$this->domain)
->groupBy('ads.id')
->orderBy('distance')
->having('distance','<','500')
->paginate(10);
}
}
它抛出
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in 'having clause' (SQL: select count(*) as aggregate from `ads` left join `categories` on `ads`.`category_id` = `categories`.`id` where `ads`.`domain` = nz group by `ads`.`id` having `distance` < 5000)