What type of user do I want to check when I log in If role is admin then redirect to admin page If role is users then redirect to home page
I using laravel/ui latest version
What type of user do I want to check when I log in If role is admin then redirect to admin page If role is users then redirect to home page
I using laravel/ui latest version
In app\Http\Controllers\LoginController.php
you can do something like this:
public function redirectTo() {
$role = auth()->user()->role;
switch ($role) {
case 'admin':
return '/admin_dashboard';
break;
case 'user':
return '/user_dashboard';
break;
default:
return '/home';
break;
}
}
Make sure you remove the line of:
protected $redirectTo = RouteServiceProvider::HOME;
. In Laravel, you can either have redirectTo
be a variable OR a function, but not both. By making it a function, you can redirect the user where they need to go based on their role.