redirect user after login based on role laravel 8 code example

Example 1: how to redirect a particular user role to a page after login laravel

public function handle($request, Closure $next, $guard = null) {  if (Auth::guard($guard)->check()) {    $role = Auth::user()->role;     switch ($role) {      case 'admin':         return redirect('/admin_dashboard');         break;      case 'seller':         return redirect('/seller_dashboard');         break;       default:         return redirect('/home');          break;    }  }  return $next($request);}

Example 2: how to redirect a particular user role to a page after login laravel

protected $redirectTo = RouteServiceProvider::HOME;

Tags:

Php Example