我在Laravel5.6中运行了php artisan make:auth
,因为众所周知,它生成了一个HomeController.php
文件。
在这里面:
public function index(){ return view('home'); }
和Route::get('/home', 'HomeController@index')->name('home');
路由定义到web.php
中。
但是由于RedirectIfAuthenticated.php
中间件,http://homestead.test/home
URI重定向到http://homestead.test/login
。因此,尽管RedirectIfAuthenticated.php
是在Kernel.php
的$routeMiddleware
属性中定义的,但它作为全局中间件工作,而不是路由中间件。
这一切为什么要发生?
我还有什么不知道的?
发布于 2018-06-11 08:35:59
如果您查看创建的控制器的构造函数,就会发现它使用的是auth
中间件。
$this->middleware('auth');
如果你在$routeMiddleware
上查看你的Kernel.php
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
这根本不涉及RedirectIfAuthenticated
。这会将任何已通过身份验证的用户重定向到某个路由之外。auth
中间件将所有未通过身份验证的用户重定向到“登录”路由。
https://stackoverflow.com/questions/50789200
复制相似问题