1 <?php namespace BookStack\Entities;
3 use BookStack\Auth\User;
9 * @property int $page_id
10 * @property string $slug
11 * @property string $book_slug
12 * @property int $created_by
13 * @property Carbon $created_at
14 * @property string $type
15 * @property string $summary
16 * @property string $markdown
17 * @property string $html
18 * @property int $revision_number
20 class PageRevision extends Model
22 protected $fillable = ['name', 'html', 'text', 'markdown', 'summary'];
25 * Get the user that created the page revision
26 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
28 public function createdBy()
30 return $this->belongsTo(User::class, 'created_by');
34 * Get the page this revision originates from.
35 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
37 public function page()
39 return $this->belongsTo(Page::class);
43 * Get the url for this revision.
44 * @param null|string $path
47 public function getUrl($path = null)
49 $url = $this->page->getUrl() . '/revisions/' . $this->id;
51 return $url . '/' . trim($path, '/');
57 * Get the previous revision for the same page if existing
58 * @return \BookStack\Entities\PageRevision|null
60 public function getPrevious()
62 $id = static::newQuery()->where('page_id', '=', $this->page_id)
63 ->where('id', '<', $this->id)
67 return static::query()->find($id);
74 * Allows checking of the exact class, Used to check entity type.
75 * Included here to align with entities in similar use cases.
76 * (Yup, Bit of an awkward hack)
80 public static function isA($type)
82 return $type === 'revision';