Looking to hire Laravel developers? Try LaraJobs
This package is not available.

laravel-list-resource-collection maintained by neclimdul

Description
Hack to allow Laravel resource collections to list scalars.
Last update
2026/04/23 04:08 (dev-main)
License
Links
Downloads
163

Comments
comments powered by Disqus

ListResourceCollection

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)
    );