1 <?php namespace BookStack;
3 class PageRevision extends Model
5 protected $fillable = ['name', 'html', 'text', 'markdown', 'summary'];
8 * Get the user that created the page revision
9 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
11 public function createdBy()
13 return $this->belongsTo(User::class, 'created_by');
17 * Get the page this revision originates from.
18 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
20 public function page()
22 return $this->belongsTo(Page::class);
26 * Get the url for this revision.
27 * @param null|string $path
30 public function getUrl($path = null)
32 $url = $this->page->getUrl() . '/revisions/' . $this->id;
34 return $url . '/' . trim($path, '/');
40 * Get the previous revision for the same page if existing
41 * @return \BookStack\PageRevision|null
43 public function getPrevious()
45 if ($id = static::where('page_id', '=', $this->page_id)->where('id', '<', $this->id)->max('id')) {
46 return static::find($id);
52 * Allows checking of the exact class, Used to check entity type.
53 * Included here to align with entities in similar use cases.
54 * (Yup, Bit of an awkward hack)
58 public static function isA($type)
60 return $type === 'revision';