]> BookStack Code Mirror - bookstack/blob - app/Book.php
Fix for getting book items
[bookstack] / app / Book.php
1 <?php
2
3 namespace Oxbow;
4
5 use Illuminate\Database\Eloquent\Model;
6
7 class Book extends Model
8 {
9
10     protected $fillable = ['name', 'description'];
11
12     public function getUrl()
13     {
14         return '/books/' . $this->slug;
15     }
16
17     public function getEditUrl()
18     {
19         return $this->getUrl() . '/edit';
20     }
21
22     public function pages()
23     {
24         return $this->hasMany('Oxbow\Page');
25     }
26
27     public function chapters()
28     {
29         return $this->hasMany('Oxbow\Chapter');
30     }
31
32     public function children()
33     {
34         $pages = $this->pages()->where('chapter_id', '=', 0)->get();
35         $chapters = $this->chapters()->get();
36         foreach($chapters as $chapter) {
37             $pages->push($chapter);
38         }
39         return $pages->sortBy('priority');
40     }
41
42 }