Skip to content

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

Merged
taylorotwell merged 1 commit into
laravel:5.8from
MattStrauss:5.8
May 3, 2019
Merged

[5.8] Fix Error Message issue for Missing Method with Alternative Route Registering Syntax#28397
taylorotwell merged 1 commit into
laravel:5.8from
MattStrauss:5.8

Conversation

@MattStrauss
Copy link
Copy Markdown

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