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

[8.x] Fix router inconsistency for namespaced route groups #34793

Merged
merged 3 commits into from
Oct 12, 2020

Conversation

imanghafoori1
Copy link
Contributor

@imanghafoori1 imanghafoori1 commented Oct 11, 2020

Following my previous PR which was rejected #34784, I wanted to shed more light on the situation.
From laravel 5.6 #24385 til laravel 8.x we can define our routes like this:

use use App\Http\Controllers\TasksController;

Route::group(['namespace' => 'Whatever'], function () {
    Route::get('{task}/edit', [TasksController::class, 'edit'])->middleware('auth');
});

and it works. The 'Whatever' namespace does NOT get appended, since we have used the array notation to refer to the controller method.

All and all, the order in which the middleware(... and get(... methods are called in the chain, should have NO effect on their behavior or how they accept parameters. (according to the docs.)

But if we only reverse the order of get and middleware method calls in the example above suddenly the 'Whatever' namespace gets appended to the controller and stops working.

use use App\Http\Controllers\TasksController;

Route::group(['namespace' => 'Whatever'], function () {
    Route::middleware('auth')->get('{task}/edit', [TasksController::class, 'edit']);
});

and that is definitely wrong.

@taylorotwell taylorotwell merged commit 6e5e36f into laravel:8.x Oct 12, 2020
@imanghafoori1 imanghafoori1 deleted the fix_router branch October 12, 2020 14:28
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