資料庫資料是這樣的:
#想透過having語句把counts > 0
的取出來;
用到分頁,所以having
後面連綴分頁函數paginate
#但是這樣報錯了:
#如果我having
後面連綴的是get()
函數則沒問題,
#是可以查到counts > 0
的資料的
#這是怎麼回事呢?
是having
後面連綴分頁函數paginate
存在的bug還是?
怎麼解決好?
巴扎黑2017-05-16 16:51:05
paginate源碼
public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
{
$page = $page ?: Paginator::resolveCurrentPage($pageName);
$total = $this->getCountForPagination($columns);
$results = $total ? $this->forPage($page, $perPage)->get($columns) : collect();
return new LengthAwarePaginator($results, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => $pageName,
]);
}
paginate預設取表裡的字段,表裡是木有counts
的
可换成skip($offset)->take($limit)