2017-04-14 13 views
0

我在Laravel的登錄表單中有這種情況,我檢查用戶帳戶是否處於活動狀態。如果用戶不活躍('active' = false)我註銷用戶(我不讓他登錄)並顯示帶有鏈接的消息,說明重新發送激活鏈接,所以此鏈接將通過查找以處理重新發送的控制器請求中的表單的電子郵件,但我得到這個錯誤的電子郵件沒有找到,因爲在請求中,電子郵件沒有被包括在內!Laravel如何在點擊鏈接後在請求中保留登錄表單數據?

然後將得到的查詢是:

"select * from用戶where電子郵件is null"因爲電子郵件沒有被保留請求內。

任何想法我做錯了什麼?

如果我只是在登錄頁面dd($request),我確實看到email屬性。但爲什麼它不包含在請求中,點擊重新發送鏈接?登錄後

LoginController.php

protected function authenticated(Request $request, $user) 
    { 
     if(!$user->active){ 
      Auth::logout(); 

      dd($request->email); /*Here I do see the email*/ 

      /*But here comes the problem, the email is not being kept in the request. Why???????????*/ 
      return redirect('/login')->with('error','Please activate your account. <a href="'.route('auth.activate.resend').'"><strong>Resend</strong></a>'); 
     } 
    } 

DD($請求)和active = 0

+request: ParameterBag {#39 ▼ #parameters: array:3 [▼ "_token" => "o8t6GYwMmW6SfjfX732weghwejSBzOdWpcMf8HOL" "email" => "[email protected]" "password" => "secreto" ] }

在這個時刻,我向重發鏈接然後

DD($請求)點擊resend按鈕

+request: ParameterBag {#46 ▼ #parameters: [] }

我看到參數部分現在是空的:(

我也試過了,LoginController.php內後, $request->request->add(['email' => $user->email]);但它也不起作用。

那麼我如何將電子郵件數據保存在請求中,以便我可以使用它從另一個控制器中的點擊鏈接?有沒有其他解決方法?

+1

你可以讓他們在會議或緩存? –

+0

是的,我試過會議,現在正在工作。感謝您的評論。 – Pathros

+0

歡迎您! –

回答

0

您可以使用RequestwithInput方法,像這樣:

return redirect('/login') 
      ->with('error','Please activate your account. <a href="'.route('auth.activate.resend').'"><strong>Resend</strong></a>') 
      ->withInput($request->except('password')); // This will not send password. 

欲瞭解更多,您可以檢查: https://laravel.com/docs/4.2/requests#old-input

相關問題