2015-07-12 21:01:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Oxbow;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Page extends Model
|
|
|
|
{
|
2015-07-12 22:31:15 +02:00
|
|
|
protected $fillable = ['name', 'html', 'priority'];
|
|
|
|
|
2015-07-20 23:05:26 +02:00
|
|
|
protected $simpleAttributes = ['name', 'id', 'slug'];
|
|
|
|
|
|
|
|
public function toSimpleArray()
|
|
|
|
{
|
|
|
|
$array = array_intersect_key($this->toArray(), array_flip($this->simpleAttributes));
|
|
|
|
$array['url'] = $this->getUrl();
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
2015-07-12 22:31:15 +02:00
|
|
|
public function book()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Oxbow\Book');
|
|
|
|
}
|
|
|
|
|
2015-07-20 23:05:26 +02:00
|
|
|
public function children()
|
|
|
|
{
|
2015-07-21 21:13:29 +02:00
|
|
|
return $this->hasMany('Oxbow\Page')->orderBy('priority', 'ASC');
|
2015-07-20 23:05:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function parent()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Oxbow\Page', 'page_id');
|
|
|
|
}
|
|
|
|
|
2015-07-12 22:31:15 +02:00
|
|
|
public function getUrl()
|
|
|
|
{
|
|
|
|
return '/books/' . $this->book->slug . '/' . $this->slug;
|
|
|
|
}
|
2015-07-20 23:05:26 +02:00
|
|
|
|
2015-07-12 21:01:42 +02:00
|
|
|
}
|