-
https://filamentphp.com/docs/2.x/admin/resources/creating-records#customizing-data-before-saving per document we can mutate form data before save into database table. I noticed that if I dd($data) . only the direct model data in the array but no relationship data.
in above sample code. when dd, data array has name and email. but not any of the relationship data such as 'mobile' and 'phone' . |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 10 replies
-
OK. it seems I figured out the alternative. what I can do is to make changes in the afterCreate() function in CreateUser class.
|
Beta Was this translation helpful? Give feedback.
-
Created a feature request to track this - #4176 |
Beta Was this translation helpful? Give feedback.
-
Hey @topegret! This has been fixed in #4424 - you can now use ->mutateRelationshipDataBeforeSaveUsing(fn (array $data) => ...) |
Beta Was this translation helpful? Give feedback.
-
Just in case if you reached this page while looking for "how to mutate Relation Manager's form" then consider overriding this function within your Relation Manager protected function configureCreateAction(Tables\Actions\CreateAction $action): void
{
parent::configureCreateAction($action);
$action->mutateFormDataUsing(function ($data) {
// Example:
unset($data['foo']);
return $data;
});
} |
Beta Was this translation helpful? Give feedback.
-
How about using CheckBoxList with BelongsToMany relationship? |
Beta Was this translation helpful? Give feedback.
-
i use mutateRelationshipDataBeforeFillUsing in group layout form, and i change with mutate .. the data not filled in update. how to resolve issue .. |
Beta Was this translation helpful? Give feedback.
Hey @topegret! This has been fixed in #4424 - you can now use
mutateRelationshipDataBeforeCreateUsing()
andmutateRelationshipDataBeforeSaveUsing()
on the Group!