Skip to content
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

[5.8] Fix Error Message issue for Missing Method with Alternative Route Registering Syntax #28397

Merged
merged 1 commit into from
May 3, 2019

Conversation

MattStrauss
Copy link

This PR was created to resolve issue #27344.

When working through the framework's Routing files it seems that the below if statement found here on the parse method of Routing/RouteAction.php, caused a problem when registering a route with the new style added by this PR. For example: Route::get('/test', [App\Http\Controllers\TestController::class, 'index']);.

if (is_callable($action)) {
            return ! is_array($action) ? ['uses' => $action] : [
                'uses' => $action[0].'@'.$action[1],
                'controller' => $action[0].'@'.$action[1],
            ];
        }

By passing true as the second argument to the is_callable function (reference to PHP built in is_callable function and its parameters can be found here), it performs a syntax only check on the $var that is passed as the first argument.

This allows the $action variable that is sent through to the parse method to pass the above if statement, which then sets the uses and controller items in the Route's action array as intended by the original PR.

Then when the route's uri is hit in the browser it returns the proper error message, like: "Method App\Http\Controllers\TestController::index does not exist." as opposed to the generic "Function () does not exist", that the original issue report mentioned.

I ran PHPUnit and all of the tests were passing, except the ones that were skipped, see below from my console:

OK, but incomplete, skipped, or risky tests!
Tests: 4085, Assertions: 9471, Skipped: 87.

P.S. This is my first PR to the Laravel Framework, apologies if there are any issues.

@driesvints driesvints changed the title Fix Error Message issue for Missing Method with Alternative Route Registering Syntax [5.8] Fix Error Message issue for Missing Method with Alternative Route Registering Syntax May 2, 2019
@taylorotwell taylorotwell merged commit c321294 into laravel:5.8 May 3, 2019
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.

2 participants