2015-07-27 15:17:08 -04:00
|
|
|
<?php namespace Oxbow;
|
|
|
|
|
|
|
|
|
2015-08-16 09:51:45 -04:00
|
|
|
class Chapter extends Entity
|
2015-07-27 15:17:08 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
protected $fillable = ['name', 'description', 'priority', 'book_id'];
|
|
|
|
|
|
|
|
public function book()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Oxbow\Book');
|
|
|
|
}
|
|
|
|
|
2015-07-30 17:27:35 -04:00
|
|
|
public function pages()
|
2015-07-27 15:17:08 -04:00
|
|
|
{
|
|
|
|
return $this->hasMany('Oxbow\Page')->orderBy('priority', 'ASC');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUrl()
|
|
|
|
{
|
|
|
|
return '/books/' . $this->book->slug . '/chapter/' . $this->slug;
|
|
|
|
}
|
|
|
|
|
2015-07-30 17:27:35 -04:00
|
|
|
public function getExcerpt($length = 100)
|
|
|
|
{
|
|
|
|
return strlen($this->description) > $length ? substr($this->description, 0, $length-3) . '...' : $this->description;
|
|
|
|
}
|
|
|
|
|
2015-07-27 15:17:08 -04:00
|
|
|
}
|