Laravel-modules: middleware auth not working in Module route

Created on 23 Jun 2018  路  2Comments  路  Source: nWidart/laravel-modules

I cannot get to work the middleware in the new created module.

This is my route file:

Route::group(['middleware' => ['auth']], function() { Route::get('/dashboard/users', 'Modules\User\Http\Controllers\UserController@index')->name('dashboardUsers'); Route::get('/dashboard/user/{id}/edit', 'Modules\User\Http\Controllers\UserController@edit')->name('dashboardEditUserView'); Route::post('/dashboard/user/{id}/edit', 'Modules\User\Http\Controllers\UserController@update')->name('dashboardEditUserView'); });

Is there something I need to do to be able to use the middleware in the module?

Most helpful comment

I had to also include the "web" guard before the auth guard in order to work:

Route::group(['middleware' => ['web','auth']], function() { Route::get('/dashboard/users', 'Modules\User\Http\Controllers\UserController@index')->name('dashboardUsers'); Route::get('/dashboard/user/{id}/edit', 'Modules\User\Http\Controllers\UserController@edit')->name('dashboardEditUserView'); Route::post('/dashboard/user/{id}/edit', 'Modules\User\Http\Controllers\UserController@update')->name('dashboardEditUserView'); });

All 2 comments

I had to also include the "web" guard before the auth guard in order to work:

Route::group(['middleware' => ['web','auth']], function() { Route::get('/dashboard/users', 'Modules\User\Http\Controllers\UserController@index')->name('dashboardUsers'); Route::get('/dashboard/user/{id}/edit', 'Modules\User\Http\Controllers\UserController@edit')->name('dashboardEditUserView'); Route::post('/dashboard/user/{id}/edit', 'Modules\User\Http\Controllers\UserController@update')->name('dashboardEditUserView'); });

I had to also include the "web" guard before the auth guard in order to work:

Route::group(['middleware' => ['web','auth']], function() { Route::get('/dashboard/users', 'Modules\User\Http\Controllers\UserController@index')->name('dashboardUsers'); Route::get('/dashboard/user/{id}/edit', 'Modules\User\Http\Controllers\UserController@edit')->name('dashboardEditUserView'); Route::post('/dashboard/user/{id}/edit', 'Modules\User\Http\Controllers\UserController@update')->name('dashboardEditUserView'); });

I also encountered exactly the same issue and your answer resolved it too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

morningmemo picture morningmemo  路  3Comments

dagulo picture dagulo  路  3Comments

pawlox picture pawlox  路  4Comments

ojasseh picture ojasseh  路  3Comments

alexandretaz picture alexandretaz  路  3Comments