Skip to content

Commit ad021d8

Browse files
authored
Simplifies collection customisation (#46217)
1 parent c99d45b commit ad021d8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Illuminate/Http/Resources/Json/JsonResource.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,24 @@ public static function make(...$parameters)
7878
*/
7979
public static function collection($resource)
8080
{
81-
return tap(new AnonymousResourceCollection($resource, static::class), function ($collection) {
81+
return tap(static::newCollection($resource), function ($collection) {
8282
if (property_exists(static::class, 'preserveKeys')) {
8383
$collection->preserveKeys = (new static([]))->preserveKeys === true;
8484
}
8585
});
8686
}
8787

88+
/**
89+
* Create a new resource collection instance.
90+
*
91+
* @param mixed $resource
92+
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
93+
*/
94+
protected static function newCollection($resource)
95+
{
96+
return new AnonymousResourceCollection($resource, static::class);
97+
}
98+
8899
/**
89100
* Resolve the resource to an array.
90101
*

0 commit comments

Comments
 (0)