]> BookStack Code Mirror - bookstack/blobdiff - app/Page.php
Page Attachments - Improved UI, Now initially complete
[bookstack] / app / Page.php
index c6978d34ba935a163fe3b037037e77e2bca94f2a..94bcce2b590d104a905b0da0be36e934d8156258 100644 (file)
@@ -54,16 +54,31 @@ class Page extends Entity
         return $this->hasMany(PageRevision::class)->where('type', '=', 'version')->orderBy('created_at', 'desc');
     }
 
+    /**
+     * Get the files attached to this page.
+     * @return \Illuminate\Database\Eloquent\Relations\HasMany
+     */
+    public function files()
+    {
+        return $this->hasMany(File::class, 'uploaded_to')->orderBy('order', 'asc');
+    }
+
     /**
      * Get the url for this page.
+     * @param string|bool $path
      * @return string
      */
-    public function getUrl()
+    public function getUrl($path = false)
     {
         $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
         $midText = $this->draft ? '/draft/' : '/page/';
         $idComponent = $this->draft ? $this->id : $this->slug;
-        return '/books/' . $bookSlug . $midText . $idComponent;
+
+        if ($path !== false) {
+            return baseUrl('/books/' . $bookSlug . $midText . $idComponent . '/' . trim($path, '/'));
+        }
+
+        return baseUrl('/books/' . $bookSlug . $midText . $idComponent);
     }
 
     /**