Skip to content

Conversation

@kukukk
Copy link

@kukukk kukukk commented Dec 6, 2025

No description provided.

Copilot AI review requested due to automatic review settings December 6, 2025 20:29
Copy link

Copilot AI left a 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 with AcceptedTypesStorage::getAcceptedTypesAndKind() for more flexible data type validation
  • Updated controller method resolution from getActionMethod() to Str::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]);
Copy link

Copilot AI Dec 6, 2025

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.

Suggested change
$controller_function = $controller_class->getMethod(Str::parseCallback($route->action['uses'])[1]);
$controller_function = $controller_class->getMethod($route->getActionMethod());

Copilot uses AI. Check for mistakes.
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]);
Copy link

Copilot AI Dec 6, 2025

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.

Copilot uses AI. Check for mistakes.
$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";
Copy link

Copilot AI Dec 6, 2025

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.

Suggested change
echo $controller_class->name, "::", $controller_function->name, "\n";

Copilot uses AI. Check for mistakes.
@kukukk kukukk changed the title Support single action controller and resource class Support single action controller, resource class and make routes availability configurable from env Dec 6, 2025
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.

1 participant