3 use Illuminate\Database\Eloquent\Model;
5 class Chapter extends Model
8 protected $fillable = ['name', 'description', 'priority', 'book_id'];
10 public function book()
12 return $this->belongsTo('Oxbow\Book');
15 public function pages()
17 return $this->hasMany('Oxbow\Page')->orderBy('priority', 'ASC');
20 public function createdBy()
22 return $this->belongsTo('Oxbow\User', 'created_by');
25 public function updatedBy()
27 return $this->belongsTo('Oxbow\User', 'updated_by');
30 public function getUrl()
32 return '/books/' . $this->book->slug . '/chapter/' . $this->slug;
35 public function getExcerpt($length = 100)
37 return strlen($this->description) > $length ? substr($this->description, 0, $length-3) . '...' : $this->description;