-
Notifications
You must be signed in to change notification settings - Fork 8
Support single action controller, resource class and make routes availability configurable from env #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/laravel-data-v4
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for single action controllers (invokable controllers) and resource classes by updating the data validation approach and controller method resolution. The changes align with Laravel Data v4's type system and add support for Laravel 12.
Key changes:
- Replaced
is_a()checks withAcceptedTypesStorage::getAcceptedTypesAndKind()for more flexible data type validation - Updated controller method resolution from
getActionMethod()toStr::parseCallback() - Added Laravel 12 to supported framework versions
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| composer.json | Added Laravel 12 (^12) to supported framework versions |
| src/Data/Operation.php | Changed controller method resolution to use Str::parseCallback() for handling single action controllers; added debug echo statement |
| src/Data/Schema.php | Replaced is_a() validation with AcceptedTypesStorage::getAcceptedTypesAndKind() to support resource classes and other data-related types |
| src/Data/Property.php | Updated data class validation to use AcceptedTypesStorage approach; removed unused LaravelData import alias |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (is_string($uses)) { | ||
| $controller_class = new ReflectionClass($route->getController()); | ||
| $controller_function = $controller_class->getMethod($route->getActionMethod()); | ||
| $controller_function = $controller_class->getMethod(Str::parseCallback($route->action['uses'])[1]); |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For single action controllers (invokable controllers), Str::parseCallback($route->action['uses']) may return [class, null] if the action doesn't contain an '@' separator. Accessing [1] could give null, causing getMethod(null) to fail.
Consider using Str::parseCallback($route->action['uses'], '__invoke')[1] to provide a default method name for invokable controllers. Alternatively, $route->getActionMethod() already handles both regular and invokable controllers correctly.
| $controller_function = $controller_class->getMethod(Str::parseCallback($route->action['uses'])[1]); | |
| $controller_function = $controller_class->getMethod($route->getActionMethod()); |
| if (is_string($uses)) { | ||
| $controller_class = new ReflectionClass($route->getController()); | ||
| $controller_function = $controller_class->getMethod($route->getActionMethod()); | ||
| $controller_function = $controller_class->getMethod(Str::parseCallback($route->action['uses'])[1]); |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test helper methodFromRoute in tests/Pest.php uses $route->getActionMethod() (line 53), but the production code now uses Str::parseCallback($route->action['uses'])[1]. This inconsistency means tests may pass while production code fails for invokable controllers.
Consider updating the test helper to use the same approach as the production code, or vice versa, to ensure tests accurately reflect production behavior.
| $controller_function = $controller_class->getMethod($route->getActionMethod()); | ||
| $controller_function = $controller_class->getMethod(Str::parseCallback($route->action['uses'])[1]); | ||
|
|
||
| echo $controller_class->name, "::", $controller_function->name, "\n"; |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This debugging echo statement should be removed before merging to production. It will output to stdout whenever an operation is created from a route, which is not appropriate for production code.
| echo $controller_class->name, "::", $controller_function->name, "\n"; |
No description provided.