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;
    }


and the Model:
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() on your Create page
Was this page helpful?