1 <?php namespace BookStack\Entities\Models;
3 use BookStack\Auth\User;
4 use BookStack\Entities\Models\Page;
10 * @property int $page_id
11 * @property string $slug
12 * @property string $book_slug
13 * @property int $created_by
14 * @property Carbon $created_at
15 * @property string $type
16 * @property string $summary
17 * @property string $markdown
18 * @property string $html
19 * @property int $revision_number
21 class PageRevision extends Model
23 protected $fillable = ['name', 'html', 'text', 'markdown', 'summary'];
26 * Get the user that created the page revision
27 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
29 public function createdBy()
31 return $this->belongsTo(User::class, 'created_by');
35 * Get the page this revision originates from.
36 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
38 public function page()
40 return $this->belongsTo(Page::class);
44 * Get the url for this revision.
45 * @param null|string $path
48 public function getUrl($path = null)
50 $url = $this->page->getUrl() . '/revisions/' . $this->id;
52 return $url . '/' . trim($path, '/');
58 * Get the previous revision for the same page if existing
59 * @return \BookStack\Entities\PageRevision|null
61 public function getPrevious()
63 $id = static::newQuery()->where('page_id', '=', $this->page_id)
64 ->where('id', '<', $this->id)
68 return static::query()->find($id);
75 * Allows checking of the exact class, Used to check entity type.
76 * Included here to align with entities in similar use cases.
77 * (Yup, Bit of an awkward hack)
81 public static function isA($type)
83 return $type === 'revision';