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:Jump to solution
One way would be to mutate the data on the relation managers CreateAction?
```php
Tables\Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data) {...
3 Replies
Solution
One way would be to mutate the data on the relation managers CreateAction?
š¤
Because the method is on the create page and a relation manager is a different Livewire component. Disstoās answer should work for you.
Thank you both. It worked. Much appreciated!