neclimdul/laravel-list-resource-collection

Hack to allow Laravel resource collections to list scalars.

Maintainers

Package info

gitlab.com/neclimdul/laravel-list-resource-collection

Issues

pkg:composer/neclimdul/laravel-list-resource-collection

Statistics

Installs: 13

Dependents: 0

Suggesters: 0

Stars: 0

2.0.0 2026-04-23 02:08 UTC

This package is auto-updated.

Last update: 2026-04-23 07:18:51 UTC


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