© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
25 replies
Mark Chaney

MutateBeforeSave with Standalone Forms, model(), and statePath()

I am doing something like
public function form(Form $form): Form
{
    return $form
        ->schema([
            Checkbox::make('managed')
                ->reactive()
                ->afterStateUpdated(function (Set $set, $state) {
                    if ($state === false) {
                        $set('housing_locator', []);
                        $set('intermediaryContacts', []);
                    }
                }),
            Select::make('housing_locator')
                ->visible(fn($get) => $get('managed'))
                ->relationship('housingLocators', 'name')
                ->reactive()
                ->afterStateUpdated(function($set) {
                    // set contacts in repeater)
                }),
            Repeater::make('intermediaryContacts')
  ->relationship('intermediaryContacts'),
        ])
        ->statePath('data')
        ->model($this->property ?? Property::class);
}
public function form(Form $form): Form
{
    return $form
        ->schema([
            Checkbox::make('managed')
                ->reactive()
                ->afterStateUpdated(function (Set $set, $state) {
                    if ($state === false) {
                        $set('housing_locator', []);
                        $set('intermediaryContacts', []);
                    }
                }),
            Select::make('housing_locator')
                ->visible(fn($get) => $get('managed'))
                ->relationship('housingLocators', 'name')
                ->reactive()
                ->afterStateUpdated(function($set) {
                    // set contacts in repeater)
                }),
            Repeater::make('intermediaryContacts')
  ->relationship('intermediaryContacts'),
        ])
        ->statePath('data')
        ->model($this->property ?? Property::class);
}
So everything is just saving directly through the model. Its working fine for adding information, but I am having an issue emptying the select and repeater when the managed field is changed back to false. Don't think simply setting them to an empty array will delete those relational entries. Thoughts?
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

AttachAction - MutateBeforeSave?
FilamentFFilament / ❓┊help
3y ago
Filament forms and Model::shouldBeStrict();
FilamentFFilament / ❓┊help
14mo ago
Wizard issue with missing $statePath
FilamentFFilament / ❓┊help
2y ago
Code Execution after successful validation for standalone forms and actions
FilamentFFilament / ❓┊help
3y ago