2017-02-14 243 views
0

登錄失敗後,我應該如何將用戶重定向到登錄頁面? 我試圖在AuthControllerLaravel 5.2:將用戶重定向到登錄頁面失敗後

protected $redirectTo ='/login'; 
protected $loginView = 'auth.login_register_form'; 
protected $loginPath = '/login'; 

,但用戶不重定向到/login頁,他被重定向回他是在
詛咒之前存在AuthenticateUser.php充當登錄的方法在網頁失敗的方法:

protected function sendFailedLoginResponse(Request $request) 
{ 
    return redirect()->back() 
     ->withInput($request->only($this->loginUsername(), 'remember')) 
     ->withErrors([ 
      $this->loginUsername() => $this->getFailedLoginMessage(), 
     ]); 
} 

,但我不能編輯此方法。這是laravel核心文件之一。

回答

1

在你的控制器,你必須回到他重定向(不僅僅是分配路徑變量),例如

return redirect('/login'); 

如果是用實心輸入形式,你可以這樣做

return redirect('/login')->withInput(); 

在你的例子

protected function sendFailedLoginResponse(Request $request) 
{ 
    return redirect('/login') 
     ->withInput($request->only($this->loginUsername(), 'remember')) 
     ->withErrors([ 
      $this->loginUsername() => $this->getFailedLoginMessage(), 
     ]); 
} 
+0

你在說「AuthController」嗎? – alex

+0

是的,如果你的驗證失敗添加重定向到你想要的頁面 – KuKeC

+0

謝謝,所以你的意思是沒有財產去做成功登錄或註銷的工作。我應該自己寫這個方法 – alex

相關問題