BookStack/app/Book.php

53 lines
997 B
PHP
Raw Normal View History

2015-07-12 19:01:42 +00: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 20:31:15 +00:00
public function pages()
{
return $this->hasMany('Oxbow\Page');
}
2015-07-27 19:17:08 +00:00
public function chapters()
{
return $this->hasMany('Oxbow\Chapter');
}
public function createdBy()
{
return $this->belongsTo('Oxbow\User', 'created_by');
}
public function updatedBy()
{
return $this->belongsTo('Oxbow\User', 'updated_by');
}
2015-07-27 19:17:08 +00:00
public function children()
{
$pages = $this->pages()->where('chapter_id', '=', 0)->get();
2015-07-27 19:17:08 +00:00
$chapters = $this->chapters()->get();
2015-07-30 22:18:48 +00:00
foreach($chapters as $chapter) {
$pages->push($chapter);
}
return $pages->sortBy('priority');
2015-07-27 19:17:08 +00:00
}
2015-07-12 19:01:42 +00:00
}