mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Merge pull request #16640 from filamentphp/fix/pivot-model-casts
fix: Pivot model casts during edit
This commit is contained in:
@@ -36,12 +36,34 @@ class EditAction extends Action
|
||||
$this->icon(FilamentIcon::resolve('actions::edit-action') ?? 'heroicon-m-pencil-square');
|
||||
|
||||
$this->fillForm(function (Model $record, Table $table): array {
|
||||
if ($translatableContentDriver = $table->makeTranslatableContentDriver()) {
|
||||
$translatableContentDriver = $table->makeTranslatableContentDriver();
|
||||
|
||||
if ($translatableContentDriver) {
|
||||
$data = $translatableContentDriver->getRecordAttributesToArray($record);
|
||||
} else {
|
||||
$data = $record->attributesToArray();
|
||||
}
|
||||
|
||||
$relationship = $table->getRelationship();
|
||||
|
||||
if ($relationship instanceof BelongsToMany) {
|
||||
$pivot = $record->getRelationValue($relationship->getPivotAccessor());
|
||||
|
||||
$pivotColumns = $relationship->getPivotColumns();
|
||||
|
||||
if ($translatableContentDriver) {
|
||||
$data = [
|
||||
...$data,
|
||||
...Arr::only($translatableContentDriver->getRecordAttributesToArray($pivot), $pivotColumns),
|
||||
];
|
||||
} else {
|
||||
$data = [
|
||||
...$data,
|
||||
...Arr::only($pivot->attributesToArray(), $pivotColumns),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->mutateRecordDataUsing) {
|
||||
$data = $this->evaluate($this->mutateRecordDataUsing, ['data' => $data]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user