Skip to content

[12.x] Add preserveKeys method to AnonymousResourceCollection#58443

Merged
taylorotwell merged 1 commit intolaravel:12.xfrom
comhon-project:12.x
Jan 21, 2026
Merged

[12.x] Add preserveKeys method to AnonymousResourceCollection#58443
taylorotwell merged 1 commit intolaravel:12.xfrom
comhon-project:12.x

Conversation

@comhon-project
Copy link
Contributor

Hey!

This method allows chaining preserveKeys() directly when returning a resource collection, instead of having to store the collection in a variable and manually set the property.

Before:

$collection = JsonResource::collection($posts);
$collection->preserveKeys = true;
return $collection;

After:

return JsonResource::collection($posts)->preserveKeys();

Cheers!

@taylorotwell taylorotwell merged commit 1bb03b6 into laravel:12.x Jan 21, 2026
70 of 72 checks passed
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.

2 participants