3 namespace BookStack\Entities\Models;
5 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 use Illuminate\Database\Eloquent\Relations\HasMany;
7 use Illuminate\Support\Collection;
12 * @property Collection<Page> $pages
13 * @property string $description
15 class Chapter extends BookChild
19 public $searchFactor = 1.2;
21 protected $fillable = ['name', 'description', 'priority', 'book_id'];
22 protected $hidden = ['restricted', 'pivot', 'deleted_at'];
25 * Get the pages that this chapter contains.
26 * @return HasMany<Page>
28 public function pages(string $dir = 'ASC'): HasMany
30 return $this->hasMany(Page::class)->orderBy('priority', $dir);
34 * Get the url of this chapter.
36 public function getUrl(string $path = ''): string
40 urlencode($this->book_slug ?? $this->book->slug),
42 urlencode($this->slug),
46 return url('/' . implode('/', $parts));
50 * Get the visible pages in this chapter.
52 public function getVisiblePages(): Collection
56 ->orderBy('draft', 'desc')
57 ->orderBy('priority', 'asc')