|null */ private ?array $values = null; public function get(string $key, mixed $default = null): mixed { return $this->all()[$key] ?? $default; } public function set(string $key, mixed $value): void { Setting::query()->updateOrCreate(['key' => $key], ['value' => $value]); $this->flush(); } /** * @param array $values */ public function setMany(array $values): void { foreach ($values as $key => $value) { Setting::query()->updateOrCreate(['key' => $key], ['value' => $value]); } $this->flush(); } /** * @return array */ public function all(): array { try { return $this->values ??= Cache::rememberForever( self::CACHE_KEY, fn () => Setting::query()->pluck('value', 'key')->all(), ); } catch (Throwable) { // Noch keine Datenbank (Web-Installer) oder vorübergehend nicht erreichbar. return []; } } public function flush(): void { $this->values = null; Cache::forget(self::CACHE_KEY); } }