1 <?php namespace BookStack;
4 class Chapter extends Entity
6 protected $fillable = ['name', 'description', 'priority', 'book_id'];
9 * Get the book this chapter is within.
10 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
12 public function book()
14 return $this->belongsTo(Book::class);
18 * Get the pages that this chapter contains.
21 public function pages()
23 return $this->hasMany(Page::class)->orderBy('priority', 'ASC');
27 * Get the url of this chapter.
30 public function getUrl()
32 $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
33 return '/books/' . $bookSlug. '/chapter/' . $this->slug;
37 * Get an excerpt of this chapter's description to the specified length or less.
41 public function getExcerpt($length = 100)
43 $description = $this->description;
44 return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;