3 namespace BookStack\Entities\Models;
5 use BookStack\Auth\User;
8 use Illuminate\Database\Eloquent\Relations\BelongsTo;
13 * @property int $page_id
14 * @property string $slug
15 * @property string $book_slug
16 * @property int $created_by
17 * @property Carbon $created_at
18 * @property Carbon $updated_at
19 * @property string $type
20 * @property string $summary
21 * @property string $markdown
22 * @property string $html
23 * @property int $revision_number
24 * @property Page $page
26 class PageRevision extends Model
28 protected $fillable = ['name', 'html', 'text', 'markdown', 'summary'];
31 * Get the user that created the page revision.
33 public function createdBy(): BelongsTo
35 return $this->belongsTo(User::class, 'created_by');
39 * Get the page this revision originates from.
41 public function page(): BelongsTo
43 return $this->belongsTo(Page::class);
47 * Get the url for this revision.
49 * @param null|string $path
53 public function getUrl($path = null)
55 $url = $this->page->getUrl() . '/revisions/' . $this->id;
57 return $url . '/' . trim($path, '/');
64 * Get the previous revision for the same page if existing.
66 * @return \BookStack\Entities\PageRevision|null
68 public function getPrevious()
70 $id = static::newQuery()->where('page_id', '=', $this->page_id)
71 ->where('id', '<', $this->id)
75 return static::query()->find($id);
82 * Allows checking of the exact class, Used to check entity type.
83 * Included here to align with entities in similar use cases.
84 * (Yup, Bit of an awkward hack).
90 public static function isA($type)
92 return $type === 'revision';