Laravel 5.5 API resources for collections (standalone data)

前端 未结 3 1636
悲&欢浪女
悲&欢浪女 2020-12-14 10:15

I was wondering if it is possible to define different data for item resource and collection resource.

For collection I only want to send [\'id\', \'title\', \

3条回答
  •  [愿得一人]
    2020-12-14 10:41

    The accepted answer works, if you are not interested in using links and meta data. If you want, simply return:

    return new PageResourceCollection(Page::paginate(10));
    

    in your controller. You should also look to eager load other dependent relationships before passing over to the resource collection.

提交回复
热议问题