[英]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
路由组)提供用户限制。
'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.