Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Add option to create macroable method for paginationInformation. #46461

Merged

Conversation

frans-slabbekoorn
Copy link
Contributor

@frans-slabbekoorn frans-slabbekoorn commented Mar 14, 2023

This pull request allows customizing pagination information without having to extend all resources to a base resource.

This way it is possible to include the paginationInformation into a mixin:

/** @mixin \Illuminate\Http\Resources\Json\ResourceCollection */
class ResourceCollectionMixin
{
    public function paginationInformation(): Closure
    {
        return fn ($request, $paginated, $default) => collect($default)->mapWithKeysRecursively(fn ($item, $key) => [Str::camel($key) => $item])->toArray();
    }
}

@frans-slabbekoorn frans-slabbekoorn changed the title Add option to create macroable method for paginationInformation. [10.x] Add option to create macroable method for paginationInformation. Mar 14, 2023
@intveldchristian
Copy link

Very nice

@taylorotwell taylorotwell merged commit 62ee2a2 into laravel:10.x Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants