redirect user after login based on role laravel 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
public function redirectTo() { $role = Auth::user()->role; switch ($role) { case 'admin': return '/admin_dashboard'; break; case 'seller': return '/seller_dashboard'; break; default: return '/home'; break; }}