slug), trim($path, '/')])); } /** * Get all pages within this book. * @return HasMany */ public function pages(): HasMany { return $this->hasMany(Page::class); } /** * Get the direct child pages of this book. */ public function directPages(): HasMany { return $this->pages()->whereNull('chapter_id'); } /** * Get all chapters within this book. * @return HasMany */ public function chapters(): HasMany { return $this->hasMany(Chapter::class) ->where('type', '=', 'chapter'); } /** * Get the shelves this book is contained within. */ public function shelves(): BelongsToMany { return $this->belongsToMany(Bookshelf::class, 'bookshelves_books', 'book_id', 'bookshelf_id'); } /** * Get the direct child items within this book. */ public function getDirectVisibleChildren(): Collection { $pages = $this->directPages()->scopes('visible')->get(); $chapters = $this->chapters()->scopes('visible')->get(); return $pages->concat($chapters)->sortBy('priority')->sortByDesc('draft'); } public function defaultTemplate(): EntityDefaultTemplate { return new EntityDefaultTemplate($this); } public function cover(): BelongsTo { return $this->belongsTo(Image::class, 'image_id'); } public function coverInfo(): EntityCover { return new EntityCover($this); } /** * Get the sort rule assigned to this container, if existing. */ public function sortRule(): BelongsTo { return $this->belongsTo(SortRule::class); } }