components([ Section::make(__('panel.settings.sections.general')) ->schema([ TextInput::make('key') ->label(__('panel.settings.fields.key')) ->disabled() ->columnSpanFull(), /* * Raw JSON rather than a key/value editor. * * A setting holds whatever it holds: `site.maintenance` is * a map containing another map of translations. A * key/value grid can only show one flat level, so it would * render the nested part as text and write that text back * on save — quietly destroying every translation of the * maintenance notice. * * Showing the value as it really is cannot lie about it, * and the `json` rule means a typo is refused rather than * stored. */ Textarea::make('value') ->label(__('panel.settings.fields.value')) ->helperText(__('panel.settings.fields.value_hint')) ->rows(12) ->columnSpanFull() ->extraInputAttributes(['class' => 'font-mono text-sm']) ->rule('json') ->formatStateUsing(fn (mixed $state): string => json_encode( $state, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES, ) ?: 'null') ->dehydrateStateUsing(fn (?string $state): mixed => json_decode( (string) $state, associative: true, )), ]), ]); } }