Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MohitDeshwal's avatar

Laravel not Redirecting after manual user Authentication?

##In LoginController.php I want to redirect user to home page.but it always shows blank page after authenticating user.

public function authenticater($data,$request)
    {
        $email=$data['email'];
        $check=User::where('email', '=',$email)->first();
        //if not found means we need to register the user

        if ($check != null) {
            // Authentication passed.....
            $id=intval($check->id);
            Auth::loginUsingId($id,true);
            //echo '<html><script>setTimeout(function(){ window.history.go(-1); }, 3000);</script></html>';
            //echo '<html><script>location.href="/";</script></html>';

             return redirect()->guest(route('home'));

        }
0 likes
8 replies
EliasSoares's avatar

Why are you using redirect guest? And you are not using password to login?! Also your code has not a fallback... so if the user is not found (do not enter on the IF, a blank page will be shown!

1 like
SaeedPrez's avatar

You probably want to use ->intended() instead of ->guest()

return redirect()->intended(route('home'));
1 like
MohitDeshwal's avatar
MohitDeshwal
OP
Best Answer
Level 1

Was using Socialite so didn't require password. that was just a part of module. btw, my mistake was: i called authenticater() from another method of controller.So,control was going to caller method.

$this->authenticater($data,$request);
        return redirect('/home');

Solved. ..

anway,thank you @ EliasSoares. :)

SaeedPrez's avatar

When a user is not authenticated and they try to access a page that requires authentication (i.e. example.com/settings) you can use redirect()->guest('login'); to redirect them to the login page and it will save example.com/settings to session. Then after they login, you redirect them using redirect()->intended('dashboard') and it will check the if the session has an intended URL, if so it will redirect them to example.com/settings and if not, it will redirect them to the dashboard.

1 like

Please or to participate in this conversation.