Open
Description
Laravel Version
11.20.0
PHP Version
8.3.16
Database Driver & Version
No response
Description
Before version 11.20.0 the following code would return null
class CommentResource extends JsonResource
{
public function toArray($request)
{
return [
'value' => $this->whenLoaded('entity', $this->resource->entity->comment),
];
}
}
If $this->resource->entity->comment
is actually null on the database, the code correctly returns the following output in the api.
{
"value": null
}
But after the related issue got merged #51342, the code doenst return null anymore; it returns the entity that is being loaded, which caused unexpected results in our source code today.
{
"value": {
// entity object
}
}
I really think that we should be able to return null if the value is actually null when using the whenLoaded function
Steps To Reproduce
Check description.