In Laravel Filament, I want to add created_by field in create operation and updated_by in update operation.
I can succeed while I create, as follows in Pages/CreateModule.php file.
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['created_by'] = auth()->id();
return $data;
}
But When I try a method similar function:
protected function mutateFormDataBeforeUpdate(array $data): array
{
$data['updated_by'] = auth()->id();
return $data;
}
does nothing.
How can I hook the update operation in Laravel Filament?
2
Answers
I found a solution. Proper place is Edit page, not create. The proper method is handleRecordUpdate.
In Pages/EditModule.php:
try this: