d

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567
ouroffice@aware.com

 

KMF

Livewire Form Builder | Laravel News

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 AppHttpLivewire;

4 

5use FilamentForms;

6use IlluminateContractsViewView;

7use LivewireComponent;

8 

9class EditPost extends Component implements FormsContractsHasForms

10{

11 use FormsConcernsInteractsWithForms;

12 

13 public Post $post;

14 

15 public $title;

16 public $content;

17 

18 public function mount(): void

19 {

20 $this->form->fill([

21 'title' => $this->post->title,

22 'content' => $this->post->content,

23 ]);

24 }

25 

26 protected function getFormSchema(): array

27 {

28 return [

29 FormsComponentsTextInput::make('title')->required(),

30 FormsComponentsMarkdownEditor::make('content'),

31 // ...

32 ];

33 }

34 

35 public function render(): View

36 {

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: AppModelsUser::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.

Credit: Source link

Previous Next
Close
Test Caption
Test Description goes like this