F
Filament3mo ago
shabxs

mutateFormDataBeforeSave() do not showing related record data. v4

I am using spatie roles with user and i am using https://filamentphp.com/docs/4.x/forms/checkbox-list#integrating-with-an-eloquent-relationship in the UserForm to update the roles along with other user details. Everything is working fine, the user is getting updated and roles are also properly getting update. (wondering how this is happening behind the scene) Now i want to perform some activity log (currently using spatie activity log and Ralph J. Smit activity plugin) Now inside protected function mutateFormDataBeforeSave(array $data): array {
// cant access related roles before saving return $data; } also inside protected function handleRecordUpdate(Model $record, array $data): Model { // $record already has updated roles return $record; } Help required 1. where to access these roles update before being associated with user model 2. When i update only roles and saves, i dont get any activity logged in (spatie), but when i change any user data, the activity is logged. Is there any way i can add activity by default on update of roles.
4 Replies
Dennis Koch
Dennis Koch3mo ago
That’s not a v4 issue. Related records were always saved directly. I think adding dehydrated(false) does the trick.
Dan Harrin
Dan Harrin3mo ago
*dehydrated() also ->saveRelationshipsUsing(null)
Dennis Koch
Dennis Koch3mo ago
I always mix them up. 50/50 chance 😅
shabxs
shabxsOP3mo ago
thank you @Dennis Koch @Dan Harrin for the replay. amazing support..

Did you find this page helpful?