資料庫資料是這樣的:
#想透過having語句把counts > 0的取出來;用到分頁,所以having後面連綴分頁函數paginate
counts > 0
having
paginate
#但是這樣報錯了:
#如果我having後面連綴的是get()函數則沒問題,
get()
#是可以查到counts > 0的資料的
#這是怎麼回事呢?
是having後面連綴分頁函數paginate存在的bug還是? 怎麼解決好?
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)
counts
skip($offset)->take($limit)
paginate源碼
paginate預設取表裡的字段,表裡是木有
counts
的可换成
skip($offset)->take($limit)