This seems like a pretty basic flow, and Laravel
has so many nice solutions for basic things, I feel like I'm missing something.
A user clicks a link that requires authentication. Laravel's auth filter kicks in and routes them to a login page. User logs in, then goes to the original page they were trying to get to before the 'auth' filter kicked in.
Is there a good way to know what page they were trying to get to originally? Since Laravel is the one intercepting the request, I didn't know if it keeps track somewhere for easy routing after the user logs in.
If not, I'd be curious to hear how some of you have implemented this manually.
Best Answer
For Laravel 5.3 and above
Check Scott's answer below.
For Laravel 5 up to 5.2
Simply put,
On auth middleware:
On login action:
For Laravel 4 (old answer)
At the time of this answer there was no official support from the framework itself. Nowadays you can use
the method pointed out by bgdrl belowthis method: (I've tried updating his answer, but it seems he won't accept)On auth filter:
On login action:
For Laravel 3 (even older answer)
You could implement it like this:
Storing the redirection on Session has the benefit of persisting it even if the user miss typed his credentials or he doesn't have an account and has to signup.
This also allows for anything else besides Auth to set a redirect on session and it will work magically.