2017-10-13 144 views
1

我刚刚升级到Laravel 5.3(从5.2开始),现在遇到了认证路由问题。Laravel 5.3认证路由重定向到/

我实现了RegisterController所需的方法,并将Auth::routes();添加到routes/web.php。但是当我访问/注册时,我总是被重定向到/

我不知道为什么,也不知道我怎么能弄清楚什么是错的。

中间件:

protected $middlewareGroups = [ 
     'web' => [ 
      \App\Http\Middleware\EncryptCookies::class, 
      \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 
      \Illuminate\Session\Middleware\StartSession::class, 
      \Illuminate\View\Middleware\ShareErrorsFromSession::class, 
      \Illuminate\Routing\Middleware\SubstituteBindings::class, 
      \App\Http\Middleware\VerifyCsrfToken::class, 
     ], 
     'api' => [ 
      'throttle:60,1', 
      'bindings', 
     ], 
    ]; 

更新:我找到了原因:我已经登录,因此它总是转发我。我仍然不知道的是,它是这样做的吗?

+0

你可以添加你的HTTP内核的'middlewareGroups'财产? – Maraboc

+0

刚刚做到了。谢谢 – Michael

回答

0

Auth :: routes()只是一个帮助类,它可以帮助您生成用户认证所需的所有路由。要更改代码,你可以浏览下面的链接:

// Authentication Routes... 
$this->get('login', 'Auth\[email protected]')->name('login'); 
$this->post('login', 'Auth\[email protected]'); 
$this->post('logout', 'Auth\[email protected]')->name('logout'); 

// Registration Routes... 
$this->get('register', 'Auth\[email protected]')->name('register'); 
$this->post('register', 'Auth\[email protected]'); 

// Password Reset Routes... 
$this->get('password/reset', 'Auth\[email protected]'); 
$this->post('password/email', 'Auth\[email protected]'); 
$this->get('password/reset/{token}', 'Auth\[email protected]'); 
$this->post('password/reset', 'Auth\[email protected]'); 

你可能要检查这个功能$this->get('register', 'Auth\[email protected]')->name('register');改变路径,或者有事情做与你的中间件。

+0

感谢您的回答,我知道这一点。控制器设置正确,中间件是默认的(请参阅更新后的问题)。 – Michael

+0

好吧,没问题。我唯一能想到的就是设置网络中间件之间的路线。不知道是什么原因导致你的问题。 –

+0

我找到了原因,但没有找到解决的办法。查看更新的问题。 – Michael

2

刚刚找到原因。

它在RedirectIfAuthenticated中间件:

if (Auth::guard($guard)->check()) { 
    return redirect('/'); 
}