Setting::query()->pluck('value', 'key')->all()); } catch (Throwable) { return $default; // e.g. before the migrations ran } return $values[$key] ?? $default; } /** * @param array $values */ public static function save(array $values): void { foreach ($values as $key => $value) { Setting::query()->updateOrCreate(['key' => $key], ['value' => $value]); } Cache::forget(self::CACHE_KEY); self::applyMailRouting(); } public static function isLive(): bool { return self::get(self::MODE, self::MODE_TEST) === self::MODE_LIVE; } /** * Where all e-mails go instead of their real recipients, or null when mails are delivered normally. * FEWO_MAIL_REDIRECT_TO in .env always wins (hard override for test servers). */ public static function mailRedirect(): ?string { $override = config('fewo.mail_redirect_to'); if (filled($override)) { return (string) $override; } if (self::isLive()) { return null; } return self::get(self::TEST_RECIPIENT) ?: (config('fewo.notification_email') ?: null); } /** * Applies the redirect to the mailer; called at boot and after saving. */ public static function applyMailRouting(): void { $manager = Mail::getFacadeRoot(); if (! $manager instanceof MailManager) { return; // Mail::fake() in tests } $redirect = self::mailRedirect(); $manager->purge(); if (filled($redirect)) { $manager->alwaysTo($redirect); } } }