普通网友 2017-04-14 02:21
浏览 284

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

I have this situation in the Laravel's login form where I check whether a user account is active or not. 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!

Then the resulting query is:

"select * fromuserswhereemailis null" because the email is not being kept inside the Request.

Any idea of what I am doing wrong?

If I dd($request) just exactly in the login page, I do see the email property. But then why isn't it being included in the request when clicking on the Resend link????

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

+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

+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]); 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?

  • 写回答

1条回答 默认 最新

  • duan6832168 2017-04-14 06:26
    关注

    You can use withInput method of Request like so:

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答