1 <?php namespace BookStack;
3 class Book extends Entity
6 protected $fillable = ['name', 'description'];
9 * Get the url for this book.
10 * @param string|bool $path
13 public function getUrl($path = false)
15 if ($path !== false) {
16 return baseUrl('/books/' . $this->slug . '/' . trim($path, '/'));
18 return baseUrl('/books/' . $this->slug);
22 * Get the edit url for this book.
25 public function getEditUrl()
27 return $this->getUrl() . '/edit';
31 * Get all pages within this book.
32 * @return \Illuminate\Database\Eloquent\Relations\HasMany
34 public function pages()
36 return $this->hasMany(Page::class);
40 * Get all chapters within this book.
41 * @return \Illuminate\Database\Eloquent\Relations\HasMany
43 public function chapters()
45 return $this->hasMany(Chapter::class);
49 * Get an excerpt of this book's description to the specified length or less.
53 public function getExcerpt($length = 100)
55 $description = $this->description;
56 return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;