*/ public array $data = []; public function mount(): void { $this->form->fill(collect(SystemSettings::EDITABLE) ->mapWithKeys(fn (array $definition, string $key): array => [self::field($key) => SystemSettings::get($key)]) ->all()); } public function form(Schema $schema): Schema { $sections = collect(SystemSettings::EDITABLE) ->groupBy(fn (array $definition): string => $definition[2], preserveKeys: true) ->map(fn ($group, string $section) => Section::make($section) ->columns(2) ->schema($group->keys()->map(fn (string $key) => $this->field_($key))->all())); return $schema ->statePath('data') ->components([ Text::make('Leer lassen heißt: der Wert aus der .env des Servers gilt wieder. Datenbank-Zugang und APP_KEY stehen bewusst nicht hier – sie werden gebraucht, um die Datenbank überhaupt zu öffnen und das Gespeicherte zu entschlüsseln.'), ...$sections->values()->all(), ]); } public function content(Schema $schema): Schema { return $schema->components([ Form::make([EmbeddedSchema::make('form')]) ->id('form') ->livewireSubmitHandler('save') ->footer([Actions::make([Action::make('save')->label('Speichern')->submit('save')])]), ]); } public function save(): void { $data = $this->form->getState(); SystemSettings::save(collect(SystemSettings::EDITABLE) ->mapWithKeys(fn (array $definition, string $key): array => [$key => $data[self::field($key)] ?? null]) ->all()); Notification::make()->title('Gespeichert')->success()->send(); } /** * Config keys contain dots, which Filament would read as nesting. */ private static function field(string $key): string { return str_replace('.', '__', $key); } private function field_(string $key): TextInput|Select { [$label, $kind, , $help] = SystemSettings::EDITABLE[$key]; $name = self::field($key); if ($kind === 'mailer') { return Select::make($name) ->label($label) ->helperText($help) ->options(['smtp' => 'SMTP (echter Versand)', 'log' => 'Nur Logdatei (kein Versand)', 'array' => 'Verwerfen (nur für Tests)']); } $field = TextInput::make($name)->label($label)->helperText($help); return match ($kind) { 'int' => $field->numeric()->integer()->minValue(0), 'secret' => $field->password()->revealable()->autocomplete(false), default => $field, }; } }