Skip to content

Commit

Permalink
Merge pull request #5639 from Laravel-Backpack/ensure-reorder-items-m…
Browse files Browse the repository at this point in the history
…atch-the-bidings

ensure reordered items match the bindings number
  • Loading branch information
pxpm authored Aug 29, 2024
2 parents c6b033e + 0d3fbaa commit 61939b9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/app/Library/CrudPanel/Traits/Reorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public function updateTreeOrder($request)
return $item;
})->toArray();

$sentIds = array_column($reorderItems, $primaryKey);

$itemKeys = $itemKeys->filter(function ($id) use ($sentIds) {
return in_array($id, $sentIds);
});

// wrap the queries in a transaction to avoid partial updates
DB::transaction(function () use ($reorderItems, $primaryKey, $itemKeys) {
// create a string of ?,?,?,? to use as bind placeholders for item keys
Expand Down

0 comments on commit 61939b9

Please # to comment.