Files
laraundfelix/app/Domain/Cms/Page.php
T
LarsandCursor 8cd382c357
Deploy Test / test (push) Successful in 15s
Deploy Test / deploy (push) Successful in 22s
Veröffentliche fachliche Säulen als Themenbereiche der Website.
Dieselbe Liste trägt die öffentliche Seite. Medien bleiben privat, Seiten können mehreren Säulen zugeordnet sein.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-15 11:46:48 +01:00

69 lines
1.7 KiB
PHP

<?php
namespace App\Domain\Cms;
use App\Domain\Catalog\Pillar;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
class Page extends Model
{
protected $fillable = [
'path',
];
public function revisions(): HasMany
{
return $this->hasMany(PageRevision::class)->latest('id');
}
public function publishedRevision(): BelongsTo
{
return $this->belongsTo(PageRevision::class, 'published_revision_id');
}
public function latestRevision(): HasOne
{
return $this->hasOne(PageRevision::class)->latestOfMany();
}
public function navigationItems(): HasMany
{
return $this->hasMany(NavigationItem::class);
}
public function isPublished(): bool
{
return $this->published_revision_id !== null;
}
public function publicUrl(): string
{
return $this->path === '/' ? url('/') : url($this->path);
}
public function publicTitle(): string
{
$revision = $this->publishedRevision;
$heading = collect($revision?->blocks ?? [])->firstWhere('type', 'heading');
if (is_string($revision?->seo_title) && $revision->seo_title !== '') {
return $revision->seo_title;
}
if (is_array($heading) && is_string($heading['heading'] ?? null) && $heading['heading'] !== '') {
return $heading['heading'];
}
return $this->path;
}
public function pillars(): BelongsToMany
{
return $this->belongsToMany(Pillar::class)->orderBy('pillars.name');
}
}