2017-05-25 21 views
0

在Laravel代碼src \照射\基金會\身份驗證\ AuthenticatesUsers.php,有一種方法如下 -

protected function authenticated(Request $request, $user) 
    { 
     // 
    } 

這種方法似乎是重定向登錄的用戶的歡迎登錄的用戶頁面,但方法是空白的。當我在這個方法中插入'return'hello user';'那麼該頁面顯示'你好用戶'。我想改變這種方法重定向到一個自定義的網址,並想知道我能在哪裏做出更改,並研究與此方法相關的其他代碼。我很難找到我正在尋找的正確代碼。

編輯:上述方法用於此方法中的三元代碼中的相同文件中。我試圖找出他們如何一起工作 -

protected function sendLoginResponse(Request $request) 
    { 
     $request->session()->regenerate(); 

     $this->clearLoginAttempts($request); 

     return $this->authenticated($request, $this->guard()->user()) 
       ?: redirect()->intended($this->redirectPath()); 
    } 
+0

你不應該在你的'src \ illuminate \ Foundation \ Auth \ AuthenticatesUsers.php'中弄亂它,它是核心laravel文件 –

+0

嘿Nikhil,你能幫我一下嗎? - https://stackoverflow.com/questions/44174928/laravel-5-4-how-do-i-redirect-logged-in-users-to-referral-url-after-successful –

+0

可能重複的[Laravel 5.4,如何在成功登錄後將登錄用戶重定向到引用URL?](https://stackoverflow.com/questions/44174928/laravel-5-4-how-do-i-redirect-logged-in-users-to-轉診網址後成功) – linktoahref

回答

1

這是因爲處理該方法繼承特質.. 如果你想在成功登錄的自定義功能的類..你可以做什麼不使用laravel登錄功能..你可以做使用驗證門面自己的登錄..

在你的LoginController例如

function myOwnLogin(Request $request) 
{ 
    $credentials= $request->only('username', 'password'); 
    if(Auth::attempt($appGrantCreds)) 
    { 
     // in this block the user is already authenticated using username and password .. 
     // so you can do your functionality here and whatsoever 
    } 
    else 
    { 
     // do your functionality for unsuccessful login 
    } 
} 

,也不要忘記設置$redirectTo = '/yourDesiredRoute';

相關問題