/**
* Class Page.
- *
+ * @property EntityPageData $pageData
* @property int $chapter_id
* @property string $html
* @property string $markdown
{
use HasFactory;
- protected $fillable = ['name', 'priority'];
-
public string $textField = 'text';
public string $htmlField = 'html';
-
- protected $hidden = ['html', 'markdown', 'text', 'pivot', 'deleted_at'];
+ protected $hidden = ['html', 'markdown', 'text', 'pivot', 'deleted_at', 'entity_id', 'entity_type'];
+ protected $fillable = ['name', 'priority'];
protected $casts = [
'draft' => 'boolean',
/**
* Get the chapter that this page is in, If applicable.
- *
- * @return BelongsTo
*/
- public function chapter()
+ public function chapter(): BelongsTo
{
return $this->belongsTo(Chapter::class);
}
/**
* Get the attachments assigned to this page.
- *
- * @return HasMany
*/
- public function attachments()
+ public function attachments(): HasMany
{
return $this->hasMany(Attachment::class, 'uploaded_to')->orderBy('order', 'asc');
}
return url('/' . implode('/', $parts));
}
+ /**
+ * Get the ID-based permalink for this page.
+ */
+ public function getPermalink(): string
+ {
+ return url("/link/{$this->id}");
+ }
+
/**
* Get this page for JSON display.
*/
$refreshed = $this->refresh()->unsetRelations()->load(['tags', 'createdBy', 'updatedBy', 'ownedBy']);
$refreshed->setHidden(array_diff($refreshed->getHidden(), ['html', 'markdown']));
$refreshed->setAttribute('raw_html', $refreshed->html);
- $refreshed->html = (new PageContent($refreshed))->render();
+ $refreshed->setAttribute('html', (new PageContent($refreshed))->render());
return $refreshed;
}
+
+ /**
+ * @return HasOne<EntityPageData, $this>
+ */
+ public function relatedData(): HasOne
+ {
+ return $this->hasOne(EntityPageData::class, 'page_id', 'id');
+ }
}