我正在使用laravel API资源。当我们不使用任何资源集合时,我们会获得带有paginate(10)的分页链接等。但是当我使用Resource :: collection时,我什么也没得到,只有我放入资源中的字段。
这是我的控制器
return response()->json([
"items" => LatestProjectsResource::collection(Project::has('pages')->where('type', $type)->latest()->paginate(20))
]);
这是我的资源
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->name,
'slug' => $this->slug,
'url' => $this->url,
'thumbnail' => new ThumbnailResource($this->thumbnail),
];
}
结果
我尝试了来自在线社区的一些答案,包括此定制Laravel 5.5 Api资源集合分页之一,但无法正常工作
我尝试过$this->collection
但没有运气
请在这里帮助我。
30秒到达战场
跃然一笑