check()) { return redirect()->route('login')->with('error', 'Please log in to access this page.'); } if (auth()->user()->is_blocked) { auth()->logout(); $request->session()->invalidate(); $request->session()->regenerateToken(); return redirect()->route('login')->with('error', 'Your account has been blocked. Please contact the administrator.'); } if (auth()->user()->role !== $role) { if (auth()->user()->role === 'admin') { if ($role === 'user') { return $next($request); } return redirect()->route('admin.dashboard'); } return redirect()->route('dashboard')->with('error', 'Unauthorized access.'); } return $next($request); } }