## 使用分頁
laravel 給我提供了非常好用的分頁工具,只需要一個方法就可以使用.paginate()接收一個數字參數,設置每頁顯示的數據條數.也可以傳遞page指定第幾頁.
~~~
return User::paginate(10);
~~~
返回樣式
~~~
{
"current_page": 1,
"data": [
{
"id": 1,
"name": "milan",
"email": "7740280@qq.com",
"created_at": "2018-02-01 14:33:57",
"updated_at": "2018-01-31 13:55:49"
},
{
"id": 2,
"name": "jack",
"email": "649781211@qq.com",
"created_at": "2018-02-01 14:33:59",
"updated_at": "2018-02-01 14:34:01"
}
],
"first_page_url": "http://sample.com/show?page=1",
"from": 1,
"last_page": 1,
"last_page_url": "http://sample.com/show?page=1",
"next_page_url": null,
"path": "http://sample.com/show",
"per_page": 10,
"prev_page_url": null,
"to": 2,
"total": 2
}
~~~
在balde模板中使用
~~~
{{$users->links()}}
~~~