laravel 給我們提供了非常方便的分頁工具----paginate分頁器
使用方法:
1.邏輯層
public function getList( $id )
{
$where = ['pid' =>$id ]
$list = $this->category->where($where)->orderBy('id','desc')->paginate(5);//$this->category對應為我的category對象,paginate函數里的參數為當前頁面需要顯示的條數
return $list;
}
2.前端頁面
只需要
<div class="pull-right paginate">
{{ $list->links() }}
</div>
只需要兩步就可以完成該功能,是不是超級簡單,如果只想顯示上一頁下一頁,不要數字的那種分頁,可以將paginate()函數替換成simplePaginate()即可