简体   繁体   English

Laravel单击链接后如何在请求中保留登录表单数据?

[英]Laravel How to keep login form data in the Request after clicking a link?

I have this situation in the Laravel's login form where I check whether a user account is active or not. 我在Laravel的登录表单中遇到这种情况,我在其中检查用户帐户是否处于活动状态。 If the user is not active ('active' = false) I log out the user (I don't let him log in) and show a message with a link saying Resend activation link , So this link takes to a controller that handles the resending by looking for the email of the form inside the request, but I am getting this error of email not found, since in the Request, the email is not being included! 如果用户未处于活动状态('active' = false)我将注销该用户(我不会让他登录),并显示一条消息,其中包含一个说“ 重新发送激活链接”的链接 ,因此该链接指向处理该问题的控制器通过在请求内查找表单的电子邮件来重新发送邮件,但由于找不到请求中的电子邮件,因此出现此错误消息,因为该电子邮件未包含在请求中!

Then the resulting query is: 然后,结果查询为:

"select * from users where email is null" because the email is not being kept inside the Request. "select * from电子邮件is null"用户where "select * from is null"因为该电子邮件未保留在请求中。

Any idea of what I am doing wrong? 任何我做错事的想法吗?

If I dd($request) just exactly in the login page, I do see the email property. 如果我恰好在登录页面中dd($request) ,我确实会看到email属性。 But then why isn't it being included in the request when clicking on the Resend link???? 但是,为什么在单击“ 重新发送”链接时为什么不将其包含在请求中?

LoginController.php 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($request) after logging in and active = 0 登录并active后的dd($ request)= 0

+request: ParameterBag {#39 ▼ #parameters: array:3 [▼ "_token" => "o8t6GYwMmW6SfjfX732weghwejSBzOdWpcMf8HOL" "email" => "me@somewhere.com" "password" => "secreto" ] }

At this moment, I show the Resend link and then 此时,我显示“ 重新发送”链接,然后

dd($request) after clicking on the resend button 单击resend按钮后的dd($ request)

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

I see that the parameters section is now empty :( 我看到参数部分现在为空:(

I have also tried, inside the LoginController.php, $request->request->add(['email' => $user->email]); 我还尝试了在LoginController.php中, $request->request->add(['email' => $user->email]); but it doesn't work either. 但它也不起作用。

Then how do I keep the email data in the Request so I can use it from a clicked link in another controller??? 然后,如何将电子邮件数据保留在“请求”中,以便可以从另一个控制器中单击的链接使用它? Is there any other workaround? 还有其他解决方法吗?

You can use withInput method of Request like so: 您可以使用Request withInput方法,如下所示:

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.

For more you can check : https://laravel.com/docs/4.2/requests#old-input 有关更多信息,请检查: https : //laravel.com/docs/4.2/requests#old-input

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM