]> BookStack Code Mirror - bookstack/blob - app/Chapter.php
ce131f3148d38686727b8ce160b43a30240c310c
[bookstack] / app / Chapter.php
1 <?php namespace BookStack;
2
3
4 class Chapter extends Entity
5 {
6
7     protected $fillable = ['name', 'description', 'priority', 'book_id'];
8
9     public function book()
10     {
11         return $this->belongsTo('BookStack\Book');
12     }
13
14     public function pages()
15     {
16         return $this->hasMany('BookStack\Page')->orderBy('priority', 'ASC');
17     }
18
19     public function getUrl()
20     {
21         return '/books/' . $this->book->slug . '/chapter/' . $this->slug;
22     }
23
24     public function getExcerpt($length = 100)
25     {
26         return strlen($this->description) > $length ? substr($this->description, 0, $length-3) . '...' : $this->description;
27     }
28
29 }