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::applyAddressOverrides(); self::applyMailRouting(); } /** * The recipients of internal notifications (admin setting, else FEWO_NOTIFICATION_EMAIL). * * @return list */ public static function notificationRecipients(): array { return self::addressList(self::get(self::NOTIFICATION_RECIPIENTS) ?: (string) config('fewo.notification_email')); } /** * "a@x.de, b@y.de; c@z.de" → valid addresses only. * * @return list */ public static function addressList(?string $value): array { return array_values(array_filter( array_map('trim', preg_split('/[,;\s]+/', (string) $value) ?: []), fn (string $address): bool => filter_var($address, FILTER_VALIDATE_EMAIL) !== false, )); } /** * Admin settings for the contact address and the sender override the .env values for this request. */ public static function applyAddressOverrides(): void { $overrides = array_filter([ 'fewo.owner.email' => self::get(self::CONTACT_EMAIL), 'mail.from.address' => self::get(self::SENDER_EMAIL), 'mail.from.name' => self::get(self::SENDER_NAME), ]); if ($overrides !== []) { config($overrides); } } 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) ?: (self::notificationRecipients()[0] ?? 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); } } }