mutateFormDataBeforeCreate not running on create from Relation Manager

I have a Filament resource and in its Create page I implemented the mutateFormDataBeforeCreate method to populate the user_id from the auth object. Ex: $data['user_id'] = auth()->id(); It works well and gets populated on Resource create. However, I also have a RelationManager on a related Model for this same Resource and when I click the create action and complete the form the user_id is missing and the create fails because its a required field in the db. Why is that? Am I missing something?
Solution:
One way would be to mutate the data on the relation managers CreateAction? ```php Tables\Actions\CreateAction::make() ->mutateFormDataUsing(function (array $data) {...
Jump to solution
3 Replies
Solution
dissto
disstoā€¢6mo ago
One way would be to mutate the data on the relation managers CreateAction?
Tables\Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data) {
$data['user_id'] = auth()->id();
return $data;
})
Tables\Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data) {
$data['user_id'] = auth()->id();
return $data;
})
šŸ¤”
Dennis Koch
Dennis Kochā€¢6mo ago
Because the method is on the create page and a relation manager is a different Livewire component. Disstoā€˜s answer should work for you.
andeancondor_74
andeancondor_74OPā€¢6mo ago
Thank you both. It worked. Much appreciated!
Want results from more Discord servers?
Add your server