get_php_workin
get_php_workin

Reputation: 450

Laravel redirect on user registration

When a user has registered his/her new account, redirect to the profile page. I know that to redirect a user to his/her account I would do:

<a href=**"account/Auth::user->username**>{{Auth::user->username}}</a>

And i figured that within Laravel's RegisterController I could do the same with its $redirectTo property, like so:

protected $redirectTo = Auth::user()->username;

But it does not seem to work, is there a way I could use the User model directly or am I missing the point?

Upvotes: 1

Views: 83

Answers (1)

Dilip Hirapara
Dilip Hirapara

Reputation: 15306

The Laravel auth system also covers that by providing a redirectTo() method that you can use instead of a $redirectTo variable.

class RegisterController extends Controller
{
    use RegistersUsers;


    protected $redirectTo = '/home';
    protected function redirectTo()
    {
        
        return 'account/'.auth()->user()->username;
    }
}

Upvotes: 2

Related Questions