ziolupo
ziolupo
Explore posts from servers
TLCTuto's Laravel Corner
Created by ziolupo on 1/26/2024 in #💡filament
Simple (modal) resource and mutateFormDataBeforeSave()
Thanks to your suggestion I was able to fine the right way. My SimpleResource is called Task and in the 'ManageTasks.php' file I added:
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data): array {
$data['user_id'] = auth()->id();
return $data;
}),
];
}
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data): array {
$data['user_id'] = auth()->id();
return $data;
}),
];
}
The above function take care of inserting the user_id during the creation process. Then I did the same in TaskResource taking care of the saving process:
->actions([
Tables\Actions\EditAction::make()
->mutateFormDataUsing(function (array $data): array {
$data['user_id'] = auth()->id();
return $data;
}),
->actions([
Tables\Actions\EditAction::make()
->mutateFormDataUsing(function (array $data): array {
$data['user_id'] = auth()->id();
return $data;
}),
Thank you so much!
5 replies