From 2ead25b542d66f5e617e576c51ea72dd87519e4f Mon Sep 17 00:00:00 2001 From: Ash Monsh Date: Sun, 9 Jun 2024 16:23:48 +0300 Subject: [PATCH] Update custom-schemata.md --- docs/advanced/custom-schemata.md | 55 +++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/docs/advanced/custom-schemata.md b/docs/advanced/custom-schemata.md index 0d949e8a..ba16fb77 100644 --- a/docs/advanced/custom-schemata.md +++ b/docs/advanced/custom-schemata.md @@ -3,7 +3,60 @@ title: Custom Schemata weight: 6 --- -## Use Custom Schemata +## Add Custom Schema for fields + +Bolt allow you to add custom form components to the form, section and fields. + +### First: create the class: + +create a class where ever you wnt in your app for example in `App\Zeus\CustomSchema` with the content: + +```php +schema([ + TextInput::make('options.field.nickname') + ->label('field nickname'), + ]); + } + + public function hidden(?FieldsContract $field = null): array + { + return [ + Hidden::make('options.field.nickname'), + ]; + } +} +``` + +- make sure to return the hidden fields the same as the fields you have defined in the `make` method +- make sure to set the `state` correctly, if you want to store these info in the `options` then use `options.more-data`, or in separate column then make sure to create the migration for it + +### Second: add it to your panel config: + +```php +BoltPlugin::make() + ->customSchema([ + 'form' => null, + 'section' => null, + 'field' => \App\Zeus\CustomSchema\Field::class, + ]) +``` + +## Replace the Schemata with Custom one the trait `Schemata` is the heart of the form builder, and now you can customize it to your liking.