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.