2015-07-12 21:01:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Oxbow;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Book extends Model
|
|
|
|
{
|
|
|
|
|
|
|
|
protected $fillable = ['name', 'description'];
|
|
|
|
|
|
|
|
public function getUrl()
|
|
|
|
{
|
|
|
|
return '/books/' . $this->slug;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEditUrl()
|
|
|
|
{
|
|
|
|
return $this->getUrl() . '/edit';
|
|
|
|
}
|
|
|
|
|
2015-07-12 22:31:15 +02:00
|
|
|
public function pages()
|
|
|
|
{
|
|
|
|
return $this->hasMany('Oxbow\Page');
|
|
|
|
}
|
|
|
|
|
2015-07-27 21:17:08 +02:00
|
|
|
public function chapters()
|
|
|
|
{
|
|
|
|
return $this->hasMany('Oxbow\Chapter');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function children()
|
|
|
|
{
|
|
|
|
$pages = $this->pages()->get();
|
|
|
|
$chapters = $this->chapters()->get();
|
|
|
|
$children = $pages->merge($chapters);
|
|
|
|
return $children->sortBy('priority');
|
|
|
|
}
|
|
|
|
|
2015-07-12 21:01:42 +02:00
|
|
|
}
|