1 <?php namespace BookStack;
4 class PageRevision extends Model
6 protected $fillable = ['name', 'html', 'text', 'markdown', 'summary'];
9 * Get the user that created the page revision
10 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
12 public function createdBy()
14 return $this->belongsTo(User::class, 'created_by');
18 * Get the page this revision originates from.
19 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
21 public function page()
23 return $this->belongsTo(Page::class);
27 * Get the url for this revision.
28 * @param null|string $path
31 public function getUrl($path = null)
33 $url = $this->page->getUrl() . '/revisions/' . $this->id;
34 if ($path) return $url . '/' . trim($path, '/');
39 * Get the previous revision for the same page if existing
40 * @return \BookStack\PageRevision|null
42 public function getPrevious()
44 if ($id = static::where('page_id', '=', $this->page_id)->where('id', '<', $this->id)->max('id')) {
45 return static::find($id);