Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Forms Laravel Package

filament/forms

Filament Forms is a Laravel package for building powerful, reactive admin forms with a fluent, component-based API. Create fields, layouts, validation, conditional logic, and dynamic interactions quickly, with tight Livewire integration and great DX for panels and apps.

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation

    composer require filament/forms
    

    Publish the package’s assets (if needed) and config:

    php artisan vendor:publish --provider="Filament\Forms\FormsServiceProvider"
    
  2. Basic Usage Create a Livewire component and use the Form facade or trait:

    use Filament\Forms\Form;
    use Livewire\Component;
    
    class MyFormComponent extends Component
    {
        public function mount()
        {
            Form::make()
                ->schema([
                    \Filament\Forms\Components\TextInput::make('name'),
                ]);
        }
    }
    
  3. First Form in a View Use the filamentForms directive in your Blade template:

    <livewire:my-form-component />
    @livewireScripts
    

Where to Look First

  • Documentation – Official Filament Forms guide.
  • Form Facade/Traits – Core class for building forms.
  • Components Namespace – Pre-built form fields (e.g., TextInput, Select, Checkbox).

Implementation Patterns

Common Workflows

  1. Dynamic Schema Build forms programmatically based on user roles or data:

    public function form()
    {
        return Form::make()
            ->schema([
                TextInput::make('email')
                    ->required()
                    ->email(),
                Select::make('role')
                    ->options(['admin', 'user'])
                    ->visible(fn () => auth()->user()->isAdmin()),
            ]);
    }
    
  2. Validation & Submission Handle form submission with Livewire’s rules() and save():

    use Illuminate\Support\Facades\Validator;
    
    public function rules()
    {
        return [
            'name' => 'required|max:255',
        ];
    }
    
    public function save()
    {
        $validated = $this->validate();
        // Process data...
    }
    
  3. Reusable Form Components Extract form logic into a dedicated class:

    class UserProfileForm
    {
        public static function make()
        {
            return Form::make()
                ->schema([
                    TextInput::make('bio')->columnSpanFull(),
                ]);
        }
    }
    
  4. Integration with Filament Admin Use in Filament panels for CRUD operations:

    use Filament\Forms\Components\TextInput;
    
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                TextInput::make('title')->required(),
            ]);
    }
    

Integration Tips

  • Livewire Hooks: Use mounted(), updated(), and render() to sync form state.
  • State Management: Leverage Livewire’s $data property for form persistence.
  • Custom Fields: Extend Filament\Forms\Components\Field for domain-specific inputs.

Gotchas and Tips

Pitfalls

  1. Schema Caching

    • Forms rebuild on every request by default. Cache the schema if performance is critical:
      public function form()
      {
          return cache()->remember('form_schema', now()->addHours(1), function () {
              return Form::make()->schema([...]);
          });
      }
      
  2. Livewire State Conflicts

    • Avoid naming form fields the same as Livewire properties (e.g., $name vs. name field).
    • Use ->key() to disambiguate:
      TextInput::make('name')->key('user_name')
      
  3. Asset Loading

    • Ensure filamentForms directive is included after @livewireScripts in Blade templates.

Debugging

  • Validation Errors: Check $errors in Livewire’s render() or use dd($this->validate()).
  • Field Visibility: Debug with ->visible(fn () => true) to test logic.
  • Console Logs: Use ->afterStateUpdated(fn () => Log::info('Updated')) for debugging.

Extension Points

  1. Custom Fields Extend Filament\Forms\Components\Field:

    class CustomField extends Field
    {
        protected string $view = 'filament.forms.custom-field';
    }
    
  2. Form Modifiers Use ->modifyQueryUsing() or ->modifyOptionsUsing() for dynamic data:

    Select::make('country')
        ->options(fn () => Country::pluck('name', 'id'))
        ->modifyQueryUsing(fn (Builder $query) => $query->whereActive(true))
    
  3. Localization Override labels/placeholders via config or ->label()/->placeholder():

    TextInput::make('name')->label(__('filament::forms.fields.name'))
    
  4. Testing Use Form::make()->fill() to simulate submissions:

    $form = Form::make()->schema([...]);
    $form->fill(['name' => 'Test']);
    $this->assertEquals('Test', $form->getState()['name']);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport