[13.x] Fix JsonApiResource relationships resolved through a closure#60752
Merged
taylorotwell merged 2 commits intoJul 14, 2026
Merged
Conversation
2b87c05 to
93889c9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR description is generated by Claude and checked by myself, just wanted to be open about that.
This PR fixes a crash when a JSON:API relationship is resolved through a closure that returns a resource:
This throws the following error:
RelationResolver::handle()only accepted a rawCollection,Model, ornull, so a closure returningCommentResource::collection(...)(anAnonymousResourceCollection) blew up on the return type before the value was ever used.The fix stays inside
RelationResolver. A returned resource collection already carries everything we need — the underlying models on itscollection, and the resource class on itscollectsproperty — so we unwrap it back into the models and adopt that resource class. A single returned resource is unwrapped the same way. This mirrors what the resolver already does internally when you hand it a class-string; the closure form was simply arriving "pre-wrapped" and the resolver didn't know how to open it.Closures that already return raw models or Eloquent collections keep working unchanged, so this is fully backward compatible — it only adds handling for return types that previously errored.
Tests are included covering a closure that returns a resource collection, a single resource, raw models, and
null.Closes #60121