label(__('filament-actions::edit.single.label')); $this->modalHeading(fn (): string => __('filament-actions::edit.single.modal.heading', ['label' => $this->getRecordTitle()])); $this->modalSubmitActionLabel(__('filament-actions::edit.single.modal.actions.save.label')); $this->successNotificationTitle(__('filament-actions::edit.single.notifications.saved.title')); $this->icon('heroicon-m-pencil-square'); $this->fillForm(function (Model $record, Table $table): array { if ($translatableContentDriver = $table->makeTranslatableContentDriver()) { $data = $translatableContentDriver->getRecordAttributesToArray($record); } else { $data = $record->attributesToArray(); } if ($this->mutateRecordDataUsing) { $data = $this->evaluate($this->mutateRecordDataUsing, ['data' => $data]); } return $data; }); $this->action(function (): void { $this->process(function (array $data, Model $record, Table $table) { $relationship = $table->getRelationship(); $translatableContentDriver = $table->makeTranslatableContentDriver(); if ($relationship instanceof BelongsToMany) { $pivotColumns = $relationship->getPivotColumns(); $pivotData = Arr::only($data, $pivotColumns); if (count($pivotColumns)) { $record->{$relationship->getPivotAccessor()}->update($pivotData); } $data = Arr::except($data, $pivotColumns); } if ($translatableContentDriver) { $translatableContentDriver->updateRecord($record, $data); } else { $record->update($data); } }); $this->success(); }); } public function mutateRecordDataUsing(?Closure $callback): static { $this->mutateRecordDataUsing = $callback; return $this; } }