© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
29 replies
Gandalf

fillForm on Create Page?

I've created a duplicate action as below:
    Tables\Actions\CreateAction::make('Duplicate')
        ->label('Duplicate')
        ->icon('heroicon-o-document-duplicate')
        ->form(fn (Form $form) => static::form($form->model(static::$model))->columns(2))
        ->fillForm(fn ($record) => $record->toArray()),
    Tables\Actions\CreateAction::make('Duplicate')
        ->label('Duplicate')
        ->icon('heroicon-o-document-duplicate')
        ->form(fn (Form $form) => static::form($form->model(static::$model))->columns(2))
        ->fillForm(fn ($record) => $record->toArray()),

Now, while this works alright for a simple resource (pop-up forms), it doesn't fill the form in case of regular resource (individual create / edit pages).

What should I do differently for it to work for regular resource?
Solution
1. Yea my bad. I was just adopting code from previous messages. You would indeed need to abstract your form fields and reuse them both in your resource and in the replicas form. For example:

public static function form(Form $form): Form
{
    return $form
        ->schema(static::getFormSchemaContent());
}
public static function form(Form $form): Form
{
    return $form
        ->schema(static::getFormSchemaContent());
}


public static function getFormSchemaContent(): array
{
    return [
        TextInput::make('dummy'),
        Select::make('another_dummy')
    ];
}
public static function getFormSchemaContent(): array
{
    return [
        TextInput::make('dummy'),
        Select::make('another_dummy')
    ];
}

Also see: https://filamentphp.com/docs/3.x/panels/resources/creating-records#sharing-fields-between-the-resource-form-and-wizards

Then you could use

ReplicateAction::make()
  ->form(static::getFormSchemaContent())
  ->fillForm(fn ($record) => $record->toArray())
  ->beforeReplicaSaved(function (Model $replica, array $data): void {
      foreach ($replica->getAttributes() as $key => $value) {
          $replica->{$key} = $data[$key] ?? $value;
      }
      $replica->save();
  })
ReplicateAction::make()
  ->form(static::getFormSchemaContent())
  ->fillForm(fn ($record) => $record->toArray())
  ->beforeReplicaSaved(function (Model $replica, array $data): void {
      foreach ($replica->getAttributes() as $key => $value) {
          $replica->{$key} = $data[$key] ?? $value;
      }
      $replica->save();
  })


2. I suppose that is related to 1 because
form(fn (Form $form) => static::form($form->model(static::$model))->columns(2))
form(fn (Form $form) => static::form($form->model(static::$model))->columns(2))
seems rather unconventional. Not sure where you got that from 🤔
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
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Create page on panel
FilamentFFilament / ❓┊help
3y ago
Add table on create page
FilamentFFilament / ❓┊help
2y ago
Create action on custom page
FilamentFFilament / ❓┊help
2y ago
livewire()->fillForm() not working
FilamentFFilament / ❓┊help
2y ago