'web' 和 'auth' 中间件的区别?

Difference between 'web' and 'auth' middleware?

我在使用 middlewareLaravel 5.2 框架时遇到了一些问题。

我的routes.php文件是:

Route::group(['prefix' => 'categories'], function () {
    Route::get('all', ['as' => 'allCategory' , 'uses' => 'CategoryController@index']);
    Route::get('add', ['as' => 'addCategory', 'uses' => 'CategoryController@create']);
    Route::get('edit/{id}', ['as' => 'editCategory', 'uses' => 'CategoryController@edit']);
    Route::post('save', ['as' => 'saveCategory', 'uses' => 'CategoryController@store']);
    Route::put('update', ['as' => 'updateCategory', 'uses' => 'CategoryController@update']);
    Route::get('delete/{id}', ['as' => 'deleteCategory', 'uses' => 'CategoryController@destroy']);

});

Route::group(['middleware' => ['web']], function () {

    Route::get('/', function () {
        return view('welcome');
    });

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

});

我在这里使用laravel默认值login/registrationauthentication.Usingphp artisan make:authcommand.I想给用户限制对于某些 routes 例如 categories 路线 group.So,

  1. 如何限制类别路由组的用户?
  2. 如果我使用 Route::group(['middleware' => ['auth']], function () { }); 然后我得到一个错误。那么'web'有什么区别 和 'auth' middleware ?

谢谢。

N.B :如果您需要了解任何文件,请在下方评论我,我会添加这些文件。

这是laravel 5.2的一个特点。 2 默认中间件是 web 和 api.

您需要在 web 中间件中放置类别组路由。

Web 中间件使您的请求包含 cookie,session,csrf_token 用于身份验证。否则,api 中间件用于简单查询获取的应用程序或 post 无请求 header,假设移动应用程序。

授权中间件基于网络中间件。