[13.x] Remove the unused Request import from the JSON:API resource stub - #61434
Merged
taylorotwell merged 1 commit intoSep 4, 2026
Merged
Conversation
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.
make:resource --json-apigenerates a class that importsIlluminate\Http\Requestand never uses it. The stub has notoArray(), only the$attributesand$relationshipsproperties, so nothing in the generated file refers toRequestat all. With Pint in CI that file failsno_unused_importsimmediately after generation, before anyone has written a line into it — the rule is on in the defaultlaravelpreset. The framework's own style pass does not reach it, which is presumably how it survived:pint.jsonhere turnsno_unused_importson as well, but Pint walks*.php, and all sixty-one files in that stubs directory end in.stub.The import looks like it came along for the ride:
resource.stubandresource-collection.stubnext to it both declarepublic function toArray(Request $request): array, and the JSON:API stub was given the same header without the method that needed it. The file has not changed since #57571 added it.The other way to fix this would be to give the stub a body instead, so the import earns its place. I don't think that is the right one here:
JsonApiResourcedoes not declaretoArray()— it resolves throughresolve()and reads the$attributesand$relationshipsproperties, and the per-resource hooks it does declare aretoAttributes(),toRelationships(),toId(),toType(),toLinks()andtoMeta(). A generatedtoArray()would point people at the wrong extension point, and the properties already in the stub are the intended one. So this is a one-line removal.There were no generator tests covering
--json-api, so I added one alongside the two that were already there. It asserts the generated class extendsJsonApiResourceand that theRequestimport is not in it, which is what would have caught this in the first place.