neclimdul/laravel-list-resource-collection
最新稳定版本:2.0.0
Composer 安装命令:
composer require neclimdul/laravel-list-resource-collection
包简介
Hack to allow Laravel resource collections to list scalars.
README 文档
README
Summary
When returning a paged results from Laravel, you're given a lot of tools using Resources to interact with Eloquents pager and provide rich, consistent JSON results. However, it assumes all your results are an array or objects. If you want to return a list of scalars, for example a list of IDs, it breaks.
This hacks package provides a Resource collection that hacks this process to allow a list of unprocesses scalars.
There's probably a better way, or maybe Laravel could better support this out of the box, but this solved the problem in the short term.
Example
<?php
$contacts = Contact::query()
->paginate(100, ['uuid']);
$contacts->setCollection($contacts->getCollection()->pluck('uuid'));
return new PaginatedResourceResponse(
ListResourceCollection::collection($contacts)
);
统计信息
- 总下载量: 27
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2026-04-23