]> BookStack Code Mirror - bookstack/blobdiff - app/Page.php
Got the tree view working
[bookstack] / app / Page.php
index d14f715204823c972cfa0105c53f306bf6910a54..3d9e6e3b2af9789c48be6c90a1bf72b56850ac30 100644 (file)
@@ -8,13 +8,33 @@ class Page extends Model
 {
     protected $fillable = ['name', 'html', 'priority'];
 
+    protected $simpleAttributes = ['name', 'id', 'slug'];
+
+    public function toSimpleArray()
+    {
+        $array = array_intersect_key($this->toArray(), array_flip($this->simpleAttributes));
+        $array['url'] = $this->getUrl();
+        return $array;
+    }
+
     public function book()
     {
         return $this->belongsTo('Oxbow\Book');
     }
 
+    public function children()
+    {
+        return $this->hasMany('Oxbow\Page');
+    }
+
+    public function parent()
+    {
+        return $this->belongsTo('Oxbow\Page', 'page_id');
+    }
+
     public function getUrl()
     {
         return '/books/' . $this->book->slug . '/' . $this->slug;
     }
+
 }