如何在资源页面中显示分页链接



我有一个资源在这个资源我有一个集合,现在我想显示该集合的分页链接,我该怎么做?

这是我的资源

public function toArray($request)
{

return [
"name"              =>  $this->name ,
"slug"              =>  $this->slug ,
"bg_image"          =>  imageGenerate("sections" , $this->bg_image) ,
"bg_color"          =>  $this->bg_color ,
"items"             =>  new ItemCollection($this->items()->paginate(20)) ,
];
}

this is my collection

public function toArray($request)
{
return $this->collection->map(function ($item) {
return [
"id"            =>  $item->id ,
"name"          =>  $item->name ,
"slug"          =>  $item->slug ,
"image"         =>  imageGenerate("items" , $item->image) ,
"code"          =>  $item->code ,
"category"      =>  $item->category->name??""
];
});
}

根据Laravel 8。在x文档中,可以传入希望分页到新创建的Collection实例的数据。下面是一个例子:

use AppHttpResourcesUserCollection;
use AppModelsUser;
Route::get('/users', function () {
return new UserCollection(User::paginate());
});

另见

相关内容

  • 没有找到相关文章

最新更新