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