3 namespace BookStack\Entities\Models;
5 use BookStack\Auth\User;
8 use Illuminate\Database\Eloquent\Relations\BelongsTo;
14 * @property int $page_id
15 * @property string $slug
16 * @property string $book_slug
17 * @property int $created_by
18 * @property Carbon $created_at
19 * @property Carbon $updated_at
20 * @property string $type
21 * @property string $summary
22 * @property string $markdown
23 * @property string $html
24 * @property int $revision_number
25 * @property Page $page
26 * @property-read ?User $createdBy
28 class PageRevision extends Model
30 protected $fillable = ['name', 'html', 'text', 'markdown', 'summary'];
31 protected $hidden = ['html', 'markdown', 'restricted', 'text'];
34 * Get the user that created the page revision.
36 public function createdBy(): BelongsTo
38 return $this->belongsTo(User::class, 'created_by');
42 * Get the page this revision originates from.
44 public function page(): BelongsTo
46 return $this->belongsTo(Page::class);
50 * Get the url for this revision.
52 public function getUrl(string $path = ''): string
54 return $this->page->getUrl('/revisions/' . $this->id . '/' . ltrim($path, '/'));
58 * Get the previous revision for the same page if existing.
60 public function getPrevious(): ?PageRevision
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).
78 * @deprecated Use instanceof instead.
80 public static function isA(string $type): bool
82 return $type === 'revision';