Skip to content

Commit

Permalink
Fix reordering for MorphMany relationships
Browse files Browse the repository at this point in the history
Fix reordering for MorphMany relationships
  • Loading branch information
m7moudabdel7mid committed Jul 28, 2024
1 parent 89b817d commit b6136df
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Components/Forms/CuratorPicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,10 @@ public function relationship(string | Closure $relationshipName, string | Closur
$orderColumn = $component->getOrderColumn();
$typeColumn = $component->getTypeColumn();
$typeValue = $component->getTypeValue();
$existingItems = $relationship->where($typeColumn, $typeValue)->get()->keyBy('media_id')->toArray();
$existingItems = $component->getRelationship()->where($typeColumn, $typeValue)->get()->keyBy('media_id')->toArray();
$newIds = collect($state)->pluck('id')->toArray();

$relationship->whereNotIn('media_id', $newIds)
$component->getRelationship()->whereNotIn('media_id', $newIds)
->where($typeColumn, $typeValue)
->delete();

Expand All @@ -539,7 +539,7 @@ public function relationship(string | Closure $relationshipName, string | Closur
$data[$typeColumn] = $typeValue;
}
if (isset($existingItems[$itemId])) {
$relationship->where('media_id', $itemId)->update($data);
$component->getRelationship()->where('media_id', $itemId)->update($data);
} else {
$relationship->create($data);
}
Expand Down

0 comments on commit b6136df

Please sign in to comment.