Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to Custom URL after Registration in Laravel 5.5

I am working on cart in laravel 5.5. Whenever guests click on "Add to cart", i am redirecting to login. If they have account, they will login and redirecting to product info they have selected. Otherwise they are registering. I wanted to redirect to customer selected product after registration. For Login, this is working fine.. return redirect()->intended(); For Registration intended url not working..

like image 207
Sridhar Avatar asked Nov 17 '17 07:11

Sridhar


3 Answers

In Controllers/Auth/RegisterController change protected $redirectTo = '/'; at line 30

For dynamic URL replace protected $redirectTo = '/'; with

protected function redirectTo()
{
    /* generate URL dynamicaly */.
    return '/path'; // return dynamicaly generated URL.
}

you can also use return redirect()->intended(/* default uri to redirect user goes here */);

The intended method on the redirector will redirect the user to the URL they were attempting to access before being intercepted by the authentication middleware. A fallback URI may be given to this method in case the intended destination is not available.

like image 58
Amarjit Singh Avatar answered Nov 15 '22 21:11

Amarjit Singh


Instead of

protected $redirectTo = '/home';

Your can use this method

protected function redirectTo()
{
    $userName = Auth::user()->name;
    //use your own route
    return route('user.edit', compact('userName'));
}
like image 35
Ridowan Ahmed Avatar answered Nov 15 '22 21:11

Ridowan Ahmed


Use function registered(Request $request, $user) as follows

protected function registered(Request $request, $user)
    {
        if ($redirect_to_selected_prodcut) {
            return redirect('/order/product');
        }

        return redirect()->intended();
    }
like image 2
mwa91 Avatar answered Nov 15 '22 20:11

mwa91