Skip to content

Conversation

@lorenzolosa
Copy link
Contributor

The $collection property of Illuminate\Http\Resources\Json\ResourceCollection is currently type hinted as Illuminate\Support\Collection, but it can also be null:

$missingValue = new Illuminate\Http\Resources\MissingValue();
$resource = JsonResource::collection($missingValue);
$resource->collection; // this is null

This commonly happens when doing JsonResource::collection($this->whenLoaded('relation')).

Here I'm changing the type-hinting annotation to include the null value.

@taylorotwell taylorotwell merged commit 8fb8706 into laravel:12.x Nov 17, 2025
68 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