© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
3 replies
H.Bilbao

Reuse form componenets

How can you reuse a section of components in several resources without having to paste the same code in all the resources?
Solution
You can create separate class with static method that define form fields and then call that method in multiple resources, like this:

class MyFormFields
{
  public static function form(): array
  {
    return [
      Filament\Forms\Components\TextInput::make('name'),
      ...
    ];
  }
}
class MyFormFields
{
  public static function form(): array
  {
    return [
      Filament\Forms\Components\TextInput::make('name'),
      ...
    ];
  }
}


And then in your resource class:

class YourResourceClass
{
  public static function form(Form $form): Form
  {
      return $form
          ->schema(...MyFormFields::form());
  }
}
class YourResourceClass
{
  public static function form(Form $form): Form
  {
      return $form
          ->schema(...MyFormFields::form());
  }
}
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Form schema reuse
FilamentFFilament / ❓┊help
6mo ago
How to reuse a Form Field?
FilamentFFilament / ❓┊help
2y ago
Reuse a Form Resource in createOptionForm
FilamentFFilament / ❓┊help
3y ago
Reuse resource form in another livewire component
FilamentFFilament / ❓┊help
3y ago