1 <?php namespace BookStack\Entities;
3 use BookStack\Entities\Page;
5 use BookStack\Auth\User;
7 class PageRevision extends Model
9 protected $fillable = ['name', 'html', 'text', 'markdown', 'summary'];
12 * Get the user that created the page revision
13 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
15 public function createdBy()
17 return $this->belongsTo(User::class, 'created_by');
21 * Get the page this revision originates from.
22 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
24 public function page()
26 return $this->belongsTo(Page::class);
30 * Get the url for this revision.
31 * @param null|string $path
34 public function getUrl($path = null)
36 $url = $this->page->getUrl() . '/revisions/' . $this->id;
38 return $url . '/' . trim($path, '/');
44 * Get the previous revision for the same page if existing
45 * @return \BookStack\PageRevision|null
47 public function getPrevious()
49 if ($id = static::where('page_id', '=', $this->page_id)->where('id', '<', $this->id)->max('id')) {
50 return static::find($id);
56 * Allows checking of the exact class, Used to check entity type.
57 * Included here to align with entities in similar use cases.
58 * (Yup, Bit of an awkward hack)
62 public static function isA($type)
64 return $type === 'revision';