3 namespace BookStack\Entities\Models;
5 use BookStack\Auth\User;
12 * @property int $page_id
13 * @property string $slug
14 * @property string $book_slug
15 * @property int $created_by
16 * @property Carbon $created_at
17 * @property string $type
18 * @property string $summary
19 * @property string $markdown
20 * @property string $html
21 * @property int $revision_number
23 class PageRevision extends Model
25 protected $fillable = ['name', 'html', 'text', 'markdown', 'summary'];
28 * Get the user that created the page revision.
30 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
32 public function createdBy()
34 return $this->belongsTo(User::class, 'created_by');
38 * Get the page this revision originates from.
40 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
42 public function page()
44 return $this->belongsTo(Page::class);
48 * Get the url for this revision.
50 * @param null|string $path
54 public function getUrl($path = null)
56 $url = $this->page->getUrl() . '/revisions/' . $this->id;
58 return $url . '/' . trim($path, '/');
65 * Get the previous revision for the same page if existing.
67 * @return \BookStack\Entities\PageRevision|null
69 public function getPrevious()
71 $id = static::newQuery()->where('page_id', '=', $this->page_id)
72 ->where('id', '<', $this->id)
76 return static::query()->find($id);
83 * Allows checking of the exact class, Used to check entity type.
84 * Included here to align with entities in similar use cases.
85 * (Yup, Bit of an awkward hack).
91 public static function isA($type)
93 return $type === 'revision';