1 <?php namespace BookStack\Entities;
3 use BookStack\Auth\User;
6 class PageRevision extends Model
8 protected $fillable = ['name', 'html', 'text', 'markdown', 'summary'];
11 * Get the user that created the page revision
12 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
14 public function createdBy()
16 return $this->belongsTo(User::class, 'created_by');
20 * Get the page this revision originates from.
21 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
23 public function page()
25 return $this->belongsTo(Page::class);
29 * Get the url for this revision.
30 * @param null|string $path
33 public function getUrl($path = null)
35 $url = $this->page->getUrl() . '/revisions/' . $this->id;
37 return $url . '/' . trim($path, '/');
43 * Get the previous revision for the same page if existing
44 * @return \BookStack\PageRevision|null
46 public function getPrevious()
48 if ($id = static::where('page_id', '=', $this->page_id)->where('id', '<', $this->id)->max('id')) {
49 return static::find($id);
55 * Allows checking of the exact class, Used to check entity type.
56 * Included here to align with entities in similar use cases.
57 * (Yup, Bit of an awkward hack)
61 public static function isA($type)
63 return $type === 'revision';