5 use Illuminate\Database\Eloquent\Model;
7 class Page extends Model
9 protected $fillable = ['name', 'html', 'priority'];
11 protected $simpleAttributes = ['name', 'id', 'slug'];
13 public function toSimpleArray()
15 $array = array_intersect_key($this->toArray(), array_flip($this->simpleAttributes));
16 $array['url'] = $this->getUrl();
20 public function book()
22 return $this->belongsTo('Oxbow\Book');
25 public function children()
27 return $this->hasMany('Oxbow\Page');
30 public function parent()
32 return $this->belongsTo('Oxbow\Page', 'page_id');
35 public function getUrl()
37 return '/books/' . $this->book->slug . '/' . $this->slug;