public function getNewPriority(Chapter $chapter) { $lastPage = $chapter->pages->last(); return $lastPage !== null ? $lastPage->priority + 1 : 0; }