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

alex212's avatar

Spatie Redirect After Registration

Hi,

I'm using Spatie for associating users with roles and permissions. I would like to re-direct the user after registration to different pages depending on what role they are. On my registration controller I assign the role, I'm just not sure how to redirect them depending on the role after that.

Has anyone come across a way to do this when using Spaite? There seems to be a lot of different ways to do this but I wanted a method that worked nicely with Spatie roles. I'm using Laravel 8 btw.

Currently, I just have this default route that redirects everyone to the Dashboard after registration:

Route::get( '/dashboard', function () {
    return view( 'dashboard' );
} )->middleware( [ 'auth' ] )->name( 'dashboard' );

My register user controller function:

public function store(Request $request)
    {
        $request->validate([
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'confirmed', Rules\Password::defaults()],
        ]);

        $user = User::create([
            'name' => $request->name,
            'email' => $request->email,
            'password' => Hash::make($request->password),
        ]);
		
		$user->assignRole('Influencers');
		
		$influencer = Influencer::create([
            'handle' => $user->name,
            'user_id' => $user->id,
        ]);

        event(new Registered($user));

        Auth::login($user);

        return view(RouteServiceProvider::HOME);
    }
}

I have 3 different roles.

Thanks in advance, Alex.

0 likes
4 replies
alex212's avatar

@jlrdw I'm using Breeze. I probably should have mentioned that.

alex212's avatar

@jlrdw Thank you for getting back to me. I ended up tweaking this a bit but managed to get it to do what I needed.

Many thanks, Alex.

Please or to participate in this conversation.