bolt

Add Custom Schema for fields

Bolt allows you to add custom components (additional metadata) to the form, sections, and fields.

First: create the class:

Create a class wherever you want in your app for example in App\Zeus\CustomSchema with the content:

1<?php
2 
3namespace App\Zeus\CustomSchema;
4 
5use Filament\Forms\Components\Hidden;
6use Filament\Forms\Components\TextInput;
7use LaraZeus\Accordion\Forms\Accordion;
8use LaraZeus\Bolt\Contracts\CustomSchema;
9use LaraZeus\Bolt\Fields\FieldsContract;
10 
11class Field implements CustomSchema
12{
13 public function make(?FieldsContract $field = null): Accordion
14 {
15 return Accordion::make('meta-data')
16 ->schema([
17 TextInput::make('options.meta.data_binding')
18 ->label('Data Binding'),
19 ]);
20 }
21 
22 public function hidden(?FieldsContract $field = null): array
23 {
24 return [
25 Hidden::make('options.meta.data_binding'),
26 ];
27 }
28}
  • 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 this info in the options then use `options. more data, or in a separate column then make sure to create the migration for it

Second: add it to your panel config:

1BoltPlugin::make()
2 ->customSchema([
3 'form' => null,
4 'section' => null,
5 'field' => \App\Zeus\CustomSchema\Field::class,
6 ])

Third: catch it on the FormSent event, for example:

1$event->response->fieldsResponses->each(function($fieldResponse){
2 CustomeModel::create([
3 'column' => $fieldResponse->field->options['meta']['data_binding']
4 ]);
5});

_Warning: This is a simplified example, so don't trust your user input explicitly. That could open some pretty serious security holes.

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.

Note
This is an advanced feature; please use it only when necessary since you have to mainline it manually with every update for Bolt.

First, copy the trait to your app:

copy the trait from \LaraZeus\Bolt\Concerns to your app, let say: \App\Zeus\Bolt\Concerns

Call the trait in a service provider

in your register method of your AppServiceProvider add the following:

1\LaraZeus\Bolt\Livewire\FillForms::getBoltFormDesignerUsing(\App\Zeus\Bolt\Concerns\Designer::class);

You're done. Customize the form builder to fit your needs. Remember to keep an eye on any changes in future updates so that you will avoid breaking changes.

Zeus is an open-source project. Thanks to my sponsors for helping me maintain this project.