© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
4 replies
MeniV

mutateFormDataBeforeSave doesn't initially save to.

I have a model 'Person' with a couple of columns. With mutateFormDataBeforeSave I want to save a concatenation of those columns to another db column named 'fullname'. I use this code which I added to CreatePerson.php & EditPerson.php:
  protected function mutateFormDataBeforeSave(array $data): array
    {
         $fullname_array=array($data['prefix'],$data['fname'],$data['lname'], $data['suffix'], $data['alias']);
         $data['fullname'] = implode(" ",$fullname_array);
         return $data;
    }
  protected function mutateFormDataBeforeSave(array $data): array
    {
         $fullname_array=array($data['prefix'],$data['fname'],$data['lname'], $data['suffix'], $data['alias']);
         $data['fullname'] = implode(" ",$fullname_array);
         return $data;
    }


and the Model:
class Persoon extends Model
{
    use HasFactory;
    protected $fillable = ['prefix', 'fname', 'lname', 'suffix', 'alias', 'fullname'];
}
class Persoon extends Model
{
    use HasFactory;
    protected $fillable = ['prefix', 'fname', 'lname', 'suffix', 'alias', 'fullname'];
}


When creating a new Person the fullname doesn't get saved in the db.
When (editing) and saving an already created Person the fullname does get (created and) saved.

Why doesn't it get saved using CreatePerson.php?
Solution
You can use
mutateFormDataBeforeCreate()
mutateFormDataBeforeCreate()
on your Create page
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

Textarea doesn't save
FilamentFFilament / ❓┊help
3y ago
modal doesn't save
FilamentFFilament / ❓┊help
3y ago
mutateFormDataBeforeSave
FilamentFFilament / ❓┊help
2y ago
Custom Action that calls "save" doesn't actually save the model
FilamentFFilament / ❓┊help
3y ago