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

[5.8] Check for preserveKeys when serializing a collection from a resource #27985

Merged
merged 2 commits into from
Mar 29, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
use tap
  • Loading branch information
rodrigopedra committed Mar 26, 2019
commit 502492e63ee19cc5f7cdfa07fa0d90f6cf3a567d
10 changes: 5 additions & 5 deletions src/Illuminate/Http/Resources/Json/JsonResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public static function make(...$parameters)
*/
public static function collection($resource)
{
$collection = new AnonymousResourceCollection($resource, static::class);

$collection->preserveKeys = property_exists(static::class, 'preserveKeys') && (new static([]))->preserveKeys === true;

return $collection;
return tap(new AnonymousResourceCollection($resource, static::class), function ($collection) {
if (property_exists(static::class, 'preserveKeys')) {
$collection->preserveKeys = (new static([]))->preserveKeys === true;
}
});
}

/**
Expand Down