Laravel 5.2:Web中间件应用了两次

时间:2016-05-06 09:45:36

标签: laravel-5.2 laravel-routing laravel-middleware

这是我的routes.php代码

    Route::auth();

    Route::group(['middleware' => 'web'], function () {
Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => ['auth','role:Admin']], function(){

    Route::get('/home', 'HomeController@index');

    Route::get('user/data', ['as' => 'admin.user.data','uses'=>'UserController@userData']);
    Route::resource('user', 'UserController');

    Route::get('merchant/data', ['as' => 'admin.merchant.data','uses'=>'MerchantController@merchantData']);
    Route::resource('merchant', 'MerchantController');

    Route::get('bcategory/data', ['as' => 'admin.bcategory.data','uses'=>'BusinessCategoryController@bcategoyData']);
    Route::resource('bcategory', 'BusinessCategoryController');

    Route::get('ccategory/data', ['as' => 'admin.ccategory.data','uses'=>'CouponCategoryController@ccategoyData']);
    Route::resource('ccategory', 'CouponCategoryController');

    Route::delete('image/{image}', ['as' => 'admin.image.destroy','uses'=>'ImageController@destroy']);

    Route::put('image/{image}/primary', ['as' => 'admin.image.updateprimary','uses'=>'ImageController@setPrimaryImage']);
});

Route::group(['namespace' => 'Merchant', 'prefix' => 'merchant', 'middleware' => 'role:Merchant'], function(){

 });
});

Route list in php artisan route:list

任何人都可以告诉我为什么网络路由被应用两次我只添加了一次组中间件。

2 个答案:

答案 0 :(得分:2)

进行了更改以始终在web中调用RouteServiceProvider中间件,因此无需在routes.php中指定它。

更新Documentation说:

请注意,web中间件组会自动应用于routes.php的默认RouteServiceProvider文件。 < / p>

答案 1 :(得分:0)

现在“web”中间件组应用于默认值。从您的文件route.php中删除此Route::group(['middleware' => 'web']