Thursday, April 13, 2017

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. 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" ] }

dd($request) after clicking on the resend button

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

Then how do I keep the email data in the Request so I can use it from a clicked link in another controller???



via Pathros

Advertisement