简体   繁体   English

了解laravel'auth'和'web'中间件

[英]Understanding laravel 'auth' and 'web' middleware

I have strange behavior on one of route groups I have defined eg 我在定义的某个路由组中有奇怪的行为,例如

Route::group(['prefix' => 'admin', 'middleware' => ['web','auth']], function (){
  //admin routes
 }
);

Whenever I defined 'middleware' => ['web','auth'], routes are accessible after login , but without 'web' I am redirected to / home. 每当我定义'middleware' => ['web','auth'],登录后即可访问路由,但是如果没有'web',我将被重定向到/ home。

What I thought was that , 'web' is default middleware injected ,please correct me if I am wrong. 我以为 ,“ web”是默认的中间件注入,如果我错了,请纠正我。 Otherwise there is some other setting that is affecting this behavior ? 否则还有其他设置会影响此行为吗?

Laravel comes with web middleware groups that contains common middleware you may want to apply to web UI routes. Laravel附带了web中间件组,其中包含您可能希望应用于Web UI路由的通用中间件。 the web middleware group is automatically applied to your default routes.php file by the RouteServiceProvider . web中间件组会自动应用到您的默认routes.php通过文件RouteServiceProvider

The web middleware is default now, but if you have create laravel app skeleton a while ago you have to update the route provider . 现在,Web 中间件是默认的,但是如果您不久前创建了laravel应用程序骨架,则必须更新route provider You can see the changes in this diff 您可以在此差异中看到更改

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

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