Extensions
Bolt over a simple way to build your own application around the forms, with a simple interface, called extensions
:
Extensions are hooks based classes that let you perform your logic around the forms or catch the submission and do more integrations with other apps or external APIs. for example before showing the form, or after storing the data etc...
Available Hooks:
-
canView
before displaying the form, you can do some checks. -
render
what to show at the beginning of the form, you can return a view to show more info or instructors while filling out the form.
-formComponents
return an array of filament components to add them to the form in the frontend
-
store
the store logic for the extension, insert to any DB or external API. -
postStore
this is typically used for sending only. It will be executed after saving the form -
submittedRender
this will show any info after saving the form, like a request number or more buttons and links
Creating an Extension
create a class in your app with the following content:
I will create a command later :)
1 2<?php 3 4namespace App\Zeus\Extensions; 5 6use Filament\Forms\Components\TextInput; 7use LaraZeus\Bolt\Contracts\Extension; 8use LaraZeus\Bolt\Models\Form; 9 10class Items implements Extension11{12 public function label(): string13 {14 return 'Ext Name';15 }16 17 public function canView(Form $form, array $data): bool|array|null18 {19 // abort_if ...20 // get the ext app and return it back, so you can receive it in the render21 // return [];22 }23 24 public function render(Form $form, array $data): string|null25 {26 // set any data and pas it to your view27 // $data['items'] = ...28 29 // return view();30 }31 32 public function formComponents(Form $form): array|null33 {34 return [35 TextInput::make('extensions.order_number'),36 ];37 }38 39 public function store(Form $form, array $data): array|null40 {41 /*$model = Model::create([42 'order_number' => $data['order_number'],43 // ...44 ]);*/45 46 // return these data to recive them after the form submitted47 // $data['model'] = $model;48 49 return $data;50 }51 52 public function postStore(Form $form, array $data): void53 {54 // send emails55 // fire some events56 }57 58 public function SubmittedRender(Form $form, array $data): string|null59 {60 // return view()->with('data', $data);61 }62}
Enabling The Extension
in your zeus-bolt
config file, add your extension to the array:
1'extensions' => [2 \App\Zeus\Extensions\Items::class,3],
now when creating or editing a form, you will see the tab Extensions, and you can select any extension per form.