Skip to content

Commit

Permalink
Merge pull request #6 from DissNik/patch-1
Browse files Browse the repository at this point in the history
feat: medias sorting
  • Loading branch information
alexvenga authored Dec 23, 2023
2 parents 1f0cef6 + 5068c75 commit 0234f55
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 0234f55

Please sign in to comment.