## 使用分页
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()}}
~~~