'boolean', ]; /** * All active routes ordered by type and target. */ public static function activeRoutes(): Collection { return static::where('is_active', true) ->orderBy('type') ->orderBy('target') ->get(); } /** * Check whether sandbox is active for a given domain. * True if global sandbox is active OR domain-specific rule is active. */ public static function isActiveForDomain(string $domain): bool { return static::where('is_active', true) ->where(function ($q) use ($domain) { $q->where('type', 'global') ->orWhere(function ($q2) use ($domain) { $q2->where('type', 'domain')->where('target', $domain); }); }) ->exists(); } /** * Check whether sandbox is active for a given address. * True if global is active OR domain matches OR address-specific rule exists. */ public static function isActiveForAddress(string $address): bool { $domain = substr(strrchr($address, '@'), 1) ?: ''; return static::where('is_active', true) ->where(function ($q) use ($address, $domain) { $q->where('type', 'global') ->orWhere(function ($q2) use ($domain) { $q2->where('type', 'domain')->where('target', $domain); }) ->orWhere(function ($q3) use ($address) { $q3->where('type', 'address')->where('target', $address); }); }) ->exists(); } }