- $isPage ? $this->pageRepo->changeBook($bookId, $model) : $this->chapterRepo->changeBook($bookId, $model);
- $model->priority = $index;
- if ($isPage) {
- $model->chapter_id = ($bookChild->parentChapter === false) ? 0 : $bookChild->parentChapter;
+
+ // Update models only if there's a change in parent chain or ordering.
+ if ($model->priority !== $priority || $model->book_id !== $bookId || ($isPage && $model->chapter_id !== $chapterId)) {
+ $isPage ? $this->pageRepo->changeBook($bookId, $model) : $this->chapterRepo->changeBook($bookId, $model);
+ $model->priority = $priority;
+ if ($isPage) $model->chapter_id = $chapterId;
+ $model->save();
+ $updatedModels->push($model);