public function pages() { return $this->hasMany(Page::class)->orderBy('priority', 'ASC'); }
/** * Get the child items for a chapter * @param Chapter $chapter */ public function getChildren(Chapter $chapter) { $pages = $this->permissionService->enforcePageRestrictions($chapter->pages())->get(); // Sort items with drafts first then by priority. return $pages->sortBy(function ($child, $key) { $score = $child->priority; if ($child->draft) { $score -= 100; } return $score; }); }