Laravel5.5 API 资源 怎么获取分页信息?
https://learnku.com/docs/laravel/5.5/eloquent-resources#分页
在文档所说的通过分页信息在UserCollection 中需要怎么获取啊?哪位大神给指点一下。谢谢
Route::get('/users', function () {
return new UserCollection(User::paginate(2));
});
namespace App\Http\Resources\User;
use Illuminate\Http\Resources\Json\ResourceCollection;
class UserCollection extends ResourceCollection
{
/**
*
*/
public function toArray($request)
{
return [
'data'=>UserResource::collection($this->collection),
"links"=>[ //这里的分页信息需要怎么获取啊?
"first"=> '',
"last"=> "http://example.com/pagination?page=1",
"prev"=> null,
"next"=> null
],
"meta"=>[ //这里的分页信息需要怎么获取啊?
"current_page"=> 1, //怎么获取当前是第几页?
"from"=> 1,
"last_page"=> 1,
"path"=> "http://example.com/pagination",
"per_page"=> 15,
"to"=> 10,
"total"=> 10
]
];
}
}
推荐文章: