instance('tenant_id', $tenantId); } return $next($request); } /** * Run a callback without the tenant scope. * Useful for super-admin operations that span all tenants. */ public static function withoutTenantScope(callable $callback): mixed { $previousTenantId = app('tenant_id'); // Clear the tenant context app()->instance('tenant_id', null); try { return $callback(); } finally { // Restore the previous tenant context app()->instance('tenant_id', $previousTenantId); } } /** * Get the current tenant ID. */ public static function getCurrentTenantId(): ?int { return app('tenant_id'); } /** * Check if a tenant scope is currently active. */ public static function hasTenantScope(): bool { return app('tenant_id') !== null; } }