]> BookStack Code Mirror - bookstack/blob - app/Chapter.php
Added created_by and updated_by to entities. Fixes #3
[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 createdBy()
21     {
22         return $this->belongsTo('Oxbow\User', 'created_by');
23     }
24
25     public function updatedBy()
26     {
27         return $this->belongsTo('Oxbow\User', 'updated_by');
28     }
29
30     public function getUrl()
31     {
32         return '/books/' . $this->book->slug . '/chapter/' . $this->slug;
33     }
34
35     public function getExcerpt($length = 100)
36     {
37         return strlen($this->description) > $length ? substr($this->description, 0, $length-3) . '...' : $this->description;
38     }
39
40 }