getSystemSettings->get(SystemSettingKey::TIMEZONE); // Localhost fallback if (in_array($ip, ['127.0.0.1', '::1', 'localhost'])) { return $systemTZ; } // Cache the result for 24 hours (86,400 seconds) return Cache::remember("timezone_ip_{$ip}", 86400, function () use ($ip, $systemTZ) { try { // Quick 2-second timeout so the app doesn't hang if the API is down $response = Http::timeout(2)->get("http://ip-api.com/json/{$ip}?fields=timezone"); return $response->json('timezone') ?? $systemTZ; } catch (Exception $e) { // If API fails, safely fallback to UTC return $systemTZ; } }); } }