*/ public private(set) Collection $settings; public function __construct() { $this->refresh(); } public function getOrDefault(string $settingName, ?string $default = null): string { return (string) $this->settings->get($settingName, $default); } public function refresh(): void { Cache::forget('website_settings'); try { /** @var mixed $result */ $result = Cache::remember( key: 'website_settings', ttl: now()->addMinutes(5), callback: fn () => Schema::hasTable('website_settings') ? WebsiteSetting::pluck('value', 'key') : collect() ); /** @var array $data */ $data = []; if ($result instanceof Collection) { foreach ($result as $key => $value) { $data[(string) $key] = is_scalar($value) ? (string) $value : ''; } } elseif (is_array($result)) { foreach ($result as $key => $value) { $data[(string) $key] = is_scalar($value) ? (string) $value : ''; } } $this->settings = new Collection($data); } catch (Throwable) { $this->settings = new Collection(); } } }