如何使用与下面代码中where子句相同的高级有子句?获取错误方法不存在。
$follows=$request->get('follows');
$db = DB::table('tabel_1 as tbl')
->leftJoin('table_2 as tb2', 'tbl.col1', '=', 'tb2.col1')
->leftJoin('table_3 as tb3', 'tbl.col1', '=', 'tb3.col1')
->select('tbl.col1','tbl.name','tb2.insta_followedByCount','tb3.twit_followers_count',DB::raw('SUM(tb2.insta_followedByCount+tb3.twit_followers_count) as ptotal'))
->groupBy('tbl.col1','tbl.name','tb2.insta_followedByCount','tb3.twit_followers_count')
->orderBy('ptotal', 'desc')
//->having('ptotal', '>=', 5000000)
->get();
if($follows){
$db = $db->having(function ($query) use ($follows) {
$query
->having('ptotal', '>=', $follows);
});
}
答案 0 :(得分:1)
您收到Ray
错误的原因是因为它是查询生成器的方法,而不是集合。
一旦你这样做:
Method having does not exist
$ db 值包含查询结果。如果您希望能够重用查询,请将其保存为新变量:
$db = DB::table() ... ->get();