'json', ]; private const CACHE_KEY = 'impostazioni'; /** Valore dell'impostazione, o $default se non รจ mai stata salvata. */ public static function valore(string $chiave, mixed $default = null): mixed { $tutte = Cache::rememberForever(self::CACHE_KEY, fn () => static::query()->pluck('valore', 'chiave')->all()); return $tutte[$chiave] ?? $default; } public static function imposta(string $chiave, mixed $valore): void { static::query()->updateOrCreate(['chiave' => $chiave], ['valore' => $valore]); } /** * Regola base di scontistica (%), valida per i clienti senza massimi personalizzati: * quella salvata dall'amministratore, altrimenti config/preventivi.php. * * @return array{max_1:float,max_2:float} */ public static function scontiBase(): array { return [ 'max_1' => (float) static::valore('sconti.max_1', config('preventivi.sconti.max_1')), 'max_2' => (float) static::valore('sconti.max_2', config('preventivi.sconti.max_2')), ]; } protected static function booted(): void { static::saved(fn () => Cache::forget(self::CACHE_KEY)); static::deleted(fn () => Cache::forget(self::CACHE_KEY)); } }