2017-10-13 160 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('/'); 
}