Skip to content

Commit

Permalink
feat: medias sorting
Browse files Browse the repository at this point in the history
Added the ability to sort items
  • Loading branch information
DissNik authored Dec 23, 2023
1 parent 71bacc9 commit 5068c75
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Fields/MediaLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ protected function resolveAfterApply(mixed $data): mixed

$this->removeOldMedia($data, $recentlyCreated, $oldValues);

$this->orderMedia($recentlyCreated, $oldValues);

return null;
}

Expand Down Expand Up @@ -112,4 +114,11 @@ private function addMedia(HasMedia $item, UploadedFile $file): Media
->preservingOriginal()
->toMediaCollection($this->column());
}

private function orderMedia(Collection $recentlyCreated, Collection $oldValues): void
{
$ids = $oldValues->merge($recentlyCreated)->pluck('id')->toArray();

Media::setNewOrder($ids);
}
}

0 comments on commit 5068c75

Please sign in to comment.