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);
}
/**