user ?? null; if (!$user) { Response::error('يجب تسجيل الدخول للوصول إلى هذا المورد', 'UNAUTHORIZED', 401); return null; } // Check if user role is in the allowed roles // $user->role is an object property since we cast it in AuthMiddleware if (!in_array($user->role, $roles)) { Response::error('غير مسموح لك بالقيام بهذا الإجراء', 'FORBIDDEN', 403); return null; } return $next($request); } }