2015-07-27 21:17:08 +02:00
|
|
|
<?php namespace Oxbow;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Chapter extends Model
|
|
|
|
{
|
|
|
|
|
|
|
|
protected $fillable = ['name', 'description', 'priority', 'book_id'];
|
|
|
|
|
|
|
|
public function book()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Oxbow\Book');
|
|
|
|
}
|
|
|
|
|
2015-07-30 23:27:35 +02:00
|
|
|
public function pages()
|
2015-07-27 21:17:08 +02:00
|
|
|
{
|
|
|
|
return $this->hasMany('Oxbow\Page')->orderBy('priority', 'ASC');
|
|
|
|
}
|
|
|
|
|
2015-08-08 22:28:50 +02:00
|
|
|
public function createdBy()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Oxbow\User', 'created_by');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updatedBy()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Oxbow\User', 'updated_by');
|
|
|
|
}
|
|
|
|
|
2015-07-27 21:17:08 +02:00
|
|
|
public function getUrl()
|
|
|
|
{
|
|
|
|
return '/books/' . $this->book->slug . '/chapter/' . $this->slug;
|
|
|
|
}
|
|
|
|
|
2015-07-30 23:27:35 +02:00
|
|
|
public function getExcerpt($length = 100)
|
|
|
|
{
|
|
|
|
return strlen($this->description) > $length ? substr($this->description, 0, $length-3) . '...' : $this->description;
|
|
|
|
}
|
|
|
|
|
2015-07-27 21:17:08 +02:00
|
|
|
}
|