3 namespace BookStack\Entities\Models;
5 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 use Illuminate\Support\Collection;
11 * @property Collection<Page> $pages
12 * @property mixed description
14 class Chapter extends BookChild
18 public $searchFactor = 1.3;
20 protected $fillable = ['name', 'description', 'priority', 'book_id'];
21 protected $hidden = ['restricted', 'pivot', 'deleted_at'];
24 * Get the pages that this chapter contains.
30 public function pages($dir = 'ASC')
32 return $this->hasMany(Page::class)->orderBy('priority', $dir);
36 * Get the url of this chapter.
38 public function getUrl($path = ''): string
42 urlencode($this->book_slug ?? $this->book->slug),
44 urlencode($this->slug),
48 return url('/' . implode('/', $parts));
52 * Get the visible pages in this chapter.
54 public function getVisiblePages(): Collection
56 return $this->pages()->visible()
57 ->orderBy('draft', 'desc')
58 ->orderBy('priority', 'asc')