1 <?php namespace BookStack\Entities\Models;
3 use Illuminate\Support\Collection;
7 * @property Collection<Page> $pages
9 class Chapter extends BookChild
11 public $searchFactor = 1.3;
13 protected $fillable = ['name', 'description', 'priority', 'book_id'];
14 protected $hidden = ['restricted', 'pivot', 'deleted_at'];
17 * Get the pages that this chapter contains.
21 public function pages($dir = 'ASC')
23 return $this->hasMany(Page::class)->orderBy('priority', $dir);
27 * Get the url of this chapter.
29 public function getUrl($path = ''): string
33 urlencode($this->getAttribute('bookSlug') ?? $this->book->slug),
35 urlencode($this->slug),
39 return url('/' . implode('/', $parts));
43 * Get the visible pages in this chapter.
45 public function getVisiblePages(): Collection
47 return $this->pages()->visible()
48 ->orderBy('draft', 'desc')
49 ->orderBy('priority', 'asc')