简体   繁体   English

“ Web”和“ Auth”中间件之间的区别?

[英]Difference between 'web' and 'auth' middleware?

I have faced some problem when i am going to use middleware group of Laravel 5.2 framework. 当我要使用Laravel 5.2框架的middleware组时,我遇到了一些问题。

My routes.php file is: 我的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');

});

I am using here laravel defaults login/registration authentication.Using php artisan make:auth command.I want to give user restricted for some routes such as categories route group.So, 我在这里使用laravel默认登录/注册身份验证。使用php artisan make:auth命令。我想为某些routes例如categories路由组)提供用户限制。

  1. How can i restrict a user for categories route group? 如何限制用户使用类别路由组?
  2. If i use Route::group(['middleware' => ['auth']], function () { }); 如果我使用Route :: group(['middleware'=> ['auth']],函数(){}); then i got an error. 然后我得到一个错误。 So what is the difference between 'web' and 'auth' middleware ? 那么'web''auth' middleware什么区别?

Thanks. 谢谢。

NB : If you need to know about any files then just comment me below i will add those files. 注意:如果您需要了解任何文件,请在下面评论我,我将添加这些文件。

This is a feature of laravel 5.2. 这是laravel 5.2的功能。 2 default middleware is web and api. 2个默认的中间件是Web和api。

You need place category group route inside web middleware. 您需要在Web中间件内部放置类别组路由。

Web middleware make your request contains cookies, session, csrf_token used for authentication. Web中间件使您的请求包含用于身份验证的cookie,会话,csrf_token。 Otherwise, api middleware used for application that simple query get or post without request header, assume mobile app. 否则,用于简单查询的应用程序的api中间件将在没有请求标头的情况下获取或发布,并假定为移动应用程序。

Auth middleware based on web middleware. 基于 Web中间件的Auth中间件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM