Filament Form Builder is a package you can use to build forms using the TALL (Tailwind, Alpine.js, Laravel, and Livewire) stack. This means that most of the work to create forms is done through PHP and Livewire components.
Here's a barebones example from the documentation:
1<?php 2 3namespace App\Http\Livewire; 4 5use Filament\Forms; 6use Illuminate\Contracts\View\View; 7use Livewire\Component; 8 9class EditPost extends Component implements Forms\Contracts\HasForms10{11 use Forms\Concerns\InteractsWithForms;12 13 public Post $post;14 15 public $title;16 public $content;17 18 public function mount(): void19 {20 $this->form->fill([21 'title' => $this->post->title,22 'content' => $this->post->content,23 ]);24 }25 26 protected function getFormSchema(): array27 {28 return [29 Forms\Components\TextInput::make('title')->required(),30 Forms\Components\MarkdownEditor::make('content'),31 // ...32 ];33 }34 35 public function render(): View36 {37 return view('edit-post');38 }39}
The getFormSchema()
method returns an array of fields, which includes a wide variety of field types:
- Text input
- Select
- Multi-select
- Checkbox
- Toggle
- Radio
- Date-time picker
- File upload
- Rich editor
- Markdown editor
- And more...
Fields can also define validation rules for each data point in your form, such as required, unique, exists (in the database), and a bunch more. Here's an example:
1Field::make('email')->unique()2Field::make('email')->unique(table: \App\Models\User::class)3Field::make('email')->unique(column: 'email_address')
You can even make custom validation rules using closures or classes as you can in Laravel. You can use this package as a standalone package with Livewire or as part of the Filament TALL Stack Admin Panel
Head over to the form component documentation to get started. You can view the source code of this package on GitHub.
Filed in:
0 comments:
Post a Comment
Thanks