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

Pendo's avatar
Level 10

Manually set intended() URL for login

I got another one on this issue, maybe I'm using the wrong approach so let me first explain the situation.

This project has an agenda page containing a number of items, a visitor can click an item to view the details. While logged in users can sign up for these items, a guest can not. So when a guest clicks a button "Sign up", he/she gets prompted with a modal containing a login and register button.

A logged in used would get a popup asking for a confirmation and then making a post-request to one of the routes for adding the user. Obviously, this route is auth-protected but it is in fact never a visible route. After saving the data, the user gets redirected back to the agenda item's detail page.

The issue in this situation is as follows: guests that click the "login" button from the model are redirected to the login form (as expected), however after login they are forwarded to the redirectPath from the AuthController and not the page they came from. From a previous issue I recall that the "intended URL" is set in the auth-middleware,..

So my guess is I'd have to clone this functionality and "Flash" it to the next page? But it seems an overkill to add a function to each controllers contructor (or even method) that saves the current URL? Is there something out of the box to use?

1 like
8 replies
jekinney's avatar

Redirect()->intended(). You can pass a default in the intended() too. Also if you dd the request object (not all();) you will see the previous url listed. So you could also use that.

Pendo's avatar
Level 10

Thanks! That's what I was looking for! I'm on 5.1, but I guess it won't be much different from the 5.2 example.

luis02lopez's avatar
Session::put('url.intended', URL::full());  

Directly in the blade works for me.

10 likes
clem's avatar

I'm also using:

session()->put('url.intended', $url);

But I'm wondering if there's a cleaner way to do it without relying on that string?

1 like

Please or to participate in this conversation.