kculmback's avatar

Redirecting to intended URL after registration

I have a fairly basic application that is using the register method that ships with Laravel. I've come up with a solution to redirect users to their intended url after registration (i.e. they try to get a user only area, they are redirected to that area after registration), but I wanted to see if there was a more 'Laravel' way to do it. The solution I came up with is this:

Auth\RegisterController

class RegisterController extends Controller {
    protected function redirectTo()
    {
        if (session('url.intended')) {
            return session('url.intended');
        }
        return '/';
    }

    ...
}

I've seen suggestions of using redirect()->intended('/'), but that doesn't work with the redirectTo method that you can use with Laravel's out-of-the-box registration.

Like I said, my code works, but I'm just wondering if there's a more 'Laravel' way of doing it, if I'm missing something, etc.

0 likes
2 replies
Snapey's avatar

I hope it goes without saying that you can only use the 'intended' path if middleware intercepts access to a restricted page.

This would not normally apply in a registration scenario, but your situation could be different.

Please or to participate in this conversation.