DEV Community

Discussion on: Laravel 8 Auth (Registration and Login)

Collapse
 
kingsconsult profile image
Kingsconsult • Edited

if I understand your question, that is, you have different classes of users, you want to direct them to their dashboard on login.

  1. You can write a helper function, use if statement to determine what the function returns
  2. Go to RouteServiceProvider.php in app\Providers\RouteServiceProvider public const HOME = '/dashboard';, change the '/dashboard/' to the helper function
  • grab the user's id using Auth use Illuminate\Support\Facades\Auth; $id = Auth::id();
  • how do you determine the class of the user (different user)
Collapse
 
anisahmmed profile image
Anis Ahamed

. I have used this way but it's not working. Is there any way to redirect user by using middleware

public function redirectTo()
{
$role = Auth::user()->role_id;
switch ($role) {
case '1':
return redirect(route('dashboard'));
break;
case '2':
return redirect(route('judge_dashboard'));
case '3':
return redirect(route('user_dashboard'));
default:
return '/login';
break;
}
}

Thread Thread
 
kingsconsult profile image
Kingsconsult

Hello, sorry I missed your comment, have you resolved it? you can still reach out to me, if you have not