1 <?php namespace BookStack\Entities\Models;
3 use Illuminate\Support\Collection;
7 * @property Collection<Page> $pages
8 * @property mixed description
10 class Chapter extends BookChild
12 public $searchFactor = 1.3;
14 protected $fillable = ['name', 'description', 'priority', 'book_id'];
15 protected $hidden = ['restricted', 'pivot', 'deleted_at'];
18 * Get the pages that this chapter contains.
22 public function pages($dir = 'ASC')
24 return $this->hasMany(Page::class)->orderBy('priority', $dir);
28 * Get the url of this chapter.
30 public function getUrl($path = ''): string
34 urlencode($this->getAttribute('bookSlug') ?? $this->book->slug),
36 urlencode($this->slug),
40 return url('/' . implode('/', $parts));
44 * Get the visible pages in this chapter.
46 public function getVisiblePages(): Collection
48 return $this->pages()->visible()
49 ->orderBy('draft', 'desc')
50 ->orderBy('priority', 'asc')