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 $name
16 * @property string $slug
17 * @property string $book_slug
18 * @property int $created_by
19 * @property Carbon $created_at
20 * @property Carbon $updated_at
21 * @property string $type
22 * @property string $summary
23 * @property string $markdown
24 * @property string $html
25 * @property string $text
26 * @property int $revision_number
27 * @property Page $page
28 * @property-read ?User $createdBy
30 class PageRevision extends Model
32 protected $fillable = ['name', 'text', 'summary'];
33 protected $hidden = ['html', 'markdown', 'restricted', 'text'];
36 * Get the user that created the page revision.
38 public function createdBy(): BelongsTo
40 return $this->belongsTo(User::class, 'created_by');
44 * Get the page this revision originates from.
46 public function page(): BelongsTo
48 return $this->belongsTo(Page::class);
52 * Get the url for this revision.
54 public function getUrl(string $path = ''): string
56 return $this->page->getUrl('/revisions/' . $this->id . '/' . ltrim($path, '/'));
60 * Get the previous revision for the same page if existing.
62 public function getPrevious(): ?PageRevision
64 $id = static::newQuery()->where('page_id', '=', $this->page_id)
65 ->where('id', '<', $this->id)
69 return static::query()->find($id);
76 * Allows checking of the exact class, Used to check entity type.
77 * Included here to align with entities in similar use cases.
78 * (Yup, Bit of an awkward hack).
80 * @deprecated Use instanceof instead.
82 public static function isA(string $type): bool
84 return $type === 'revision';