1 <?php namespace BookStack;
3 class Book extends Entity
6 protected $fillable = ['name', 'description'];
9 * Get the url for this book.
12 public function getUrl()
14 return '/books/' . $this->slug;
18 * Get the edit url for this book.
21 public function getEditUrl()
23 return $this->getUrl() . '/edit';
27 * Get all pages within this book.
28 * @return \Illuminate\Database\Eloquent\Relations\HasMany
30 public function pages()
32 return $this->hasMany(Page::class);
36 * Get all chapters within this book.
37 * @return \Illuminate\Database\Eloquent\Relations\HasMany
39 public function chapters()
41 return $this->hasMany(Chapter::class);
45 * Get an excerpt of this book's description to the specified length or less.
49 public function getExcerpt($length = 100)
51 $description = $this->description;
52 return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;