+ return $this->belongsTo(Book::class);
+ }
+
+ /**
+ * Get the chapter that this page is in, If applicable.
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function chapter()
+ {
+ return $this->belongsTo(Chapter::class);
+ }
+
+ /**
+ * Check if this page has a chapter.
+ * @return bool
+ */
+ public function hasChapter()
+ {
+ return $this->chapter()->count() > 0;
+ }
+
+ /**
+ * Get the associated page revisions, ordered by created date.
+ * @return mixed
+ */
+ public function revisions()
+ {
+ return $this->hasMany(PageRevision::class)->where('type', '=', 'version')->orderBy('created_at', 'desc');
+ }
+
+ /**
+ * Get the attachments assigned to this page.
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
+ */
+ public function attachments()
+ {
+ return $this->hasMany(Attachment::class, 'uploaded_to')->orderBy('order', 'asc');
+ }
+
+ public function comments() {
+ return $this->hasMany(Comment::class, 'page_id')->orderBy('created_on', 'asc');