3 namespace BookStack\Entities\Models;
5 use Illuminate\Support\Collection;
10 * @property Collection<Page> $pages
11 * @property mixed description
13 class Chapter extends BookChild
15 public $searchFactor = 1.3;
17 protected $fillable = ['name', 'description', 'priority', 'book_id'];
18 protected $hidden = ['restricted', 'pivot', 'deleted_at'];
21 * Get the pages that this chapter contains.
27 public function pages($dir = 'ASC')
29 return $this->hasMany(Page::class)->orderBy('priority', $dir);
33 * Get the url of this chapter.
35 public function getUrl($path = ''): string
39 urlencode($this->book_slug ?? $this->book->slug),
41 urlencode($this->slug),
45 return url('/' . implode('/', $parts));
49 * Get the visible pages in this chapter.
51 public function getVisiblePages(): Collection
53 return $this->pages()->visible()
54 ->orderBy('draft', 'desc')
55 ->orderBy('priority', 'asc')