BookStack/app/Page.php

36 lines
717 B
PHP
Raw Normal View History

2015-07-12 15:01:42 -04:00
<?php
namespace Oxbow;
use Illuminate\Database\Eloquent\Model;
class Page extends Model
{
2015-07-12 16:31:15 -04:00
protected $fillable = ['name', 'html', 'priority'];
2015-07-20 17:05:26 -04: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 16:31:15 -04:00
public function book()
{
return $this->belongsTo('Oxbow\Book');
}
2015-07-20 17:05:26 -04:00
public function parent()
{
return $this->belongsTo('Oxbow\Page', 'page_id');
}
2015-07-12 16:31:15 -04:00
public function getUrl()
{
2015-07-27 15:17:08 -04:00
return '/books/' . $this->book->slug . '/page/' . $this->slug;
2015-07-12 16:31:15 -04:00
}
2015-07-20 17:05:26 -04:00
2015-07-12 15:01:42 -04:00
}