diff --git a/src/Fields/BelongsToMany.php b/src/Fields/BelongsToMany.php index b8baf45e..50c1a8cf 100644 --- a/src/Fields/BelongsToMany.php +++ b/src/Fields/BelongsToMany.php @@ -83,9 +83,10 @@ public function fields(Request $request): array ); }); })->hydrate(function (Request $request, Pivot $model, mixed $value): void { - $relation = $this->getRelation($model->pivotParent); - - $model->setAttribute($relation->getRelatedPivotKeyName(), $value); + $model->setAttribute( + $this->getRelation($model->pivotParent)->getRelatedPivotKeyName(), + $value + ); })->display(function (Model $model): ?string { return $this->resolveDisplay($model); }), diff --git a/src/Fields/MorphToMany.php b/src/Fields/MorphToMany.php index 240b112d..525b0602 100644 --- a/src/Fields/MorphToMany.php +++ b/src/Fields/MorphToMany.php @@ -43,12 +43,10 @@ public function fields(Request $request): array $this->getRelation($model->pivotParent)->select($query->getModel()->getQualifiedKeyName()) ); }); - })->hydrate(function (Request $request, MorphPivot $model): void { - $relation = $this->getRelation($model->pivotParent); - + })->hydrate(function (Request $request, MorphPivot $model, mixed $value): void { $model->setAttribute( - $relation->getRelatedPivotKeyName(), - $model->related->getAttribute($relation->getRelatedKeyName()) + $this->getRelation($model->pivotParent)->getRelatedPivotKeyName(), + $value ); })->display(function (Model $model): mixed { return $this->resolveDisplay($model);