MartinZeltin
8 months ago
25
11
Laravel

Losing intended URL after using it once. Really strange behavior.

Posted 8 months ago by MartinZeltin

I am seeing some really strange behavior. I have my login() function redirect to intended() url and it is working fine until I put this line in my login.blade.php just to see what the intended URL was. Then my login() function doesn't know what the intended url was anymore. This is super strange.

My Login Controller

public function login(Request $request)
{
    .....
    // works great!
    Auth::login($user);
    return redirect()->intended('/');
}

But then I added this line in my login.blade.php and I lost my intended URL

<input type="hidden" id="target_url" value="{{ redirect()->intended()->getTargetUrl() }}">

And now when I log in I get redirected back to the home page ('/') instead of my intended target url. What is going on here?

public function login(Request $request)
{
    .....

       echo redirect()->intended()->getTargetUrl();

       // now it is simply http://localhost/project/public
       // before it was http://localhost/project/public/intended-page/

    return redirect()->intended('/');
}

Please sign in or create an account to participate in this conversation.