'Kopfzeile (Hauptnavigation)', 'footer' => 'Fußbereich: Service', 'footer_contact' => 'Fußbereich: Kontakt', 'footer_legal' => 'Fußbereich: Rechtliches', ]; /** Spaltenüberschriften im Fußbereich. */ public const FOOTER_GROUPS = [ 'footer' => 'Service', 'footer_contact' => 'Kontakt', 'footer_legal' => 'Rechtliches', ]; protected $fillable = [ 'label', 'page_id', 'url', 'placement', 'sort_order', 'is_visible', 'parent_id', ]; protected static function booted(): void { // Untermenüs gibt es nur in der Hauptnavigation. static::saving(function (NavigationItem $item): void { if ($item->placement !== 'header' && $item->getAttribute('parent_id') !== null) { $item->parent_id = null; } }); } protected function casts(): array { return [ 'is_visible' => 'boolean', ]; } public function page(): BelongsTo { return $this->belongsTo(Page::class); } public function parent(): BelongsTo { return $this->belongsTo(self::class, 'parent_id'); } public function children(): HasMany { return $this->hasMany(self::class, 'parent_id')->orderBy('sort_order')->orderBy('id'); } /** * @param Builder $query */ public function scopeVisible(Builder $query): void { $query->where('is_visible', true); } public function href(): ?string { if ($this->page !== null) { return $this->page->path === '/' ? url('/') : url($this->page->path); } if ($this->url === null || $this->url === '' || ! SafeUrl::isSafe($this->url)) { return null; } if (str_starts_with($this->url, '/')) { return url($this->url); } return $this->url; } /** * Pfad des Ziels innerhalb der Website (für die Kennzeichnung des aktiven Eintrags); null bei externen Zielen. */ public function targetPath(): ?string { if ($this->page !== null) { return $this->page->path; } if (is_string($this->url) && str_starts_with($this->url, '/') && ! str_starts_with($this->url, '//')) { $path = parse_url($this->url, PHP_URL_PATH); return is_string($path) ? '/'.trim($path, '/') : null; } return null; } }