*/ use HasFactory; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'is_default' => 'boolean', 'theme_settings' => 'array', ]; } /** * @return HasMany */ public function pages(): HasMany { return $this->hasMany(Page::class)->orderBy('sort_order'); } /** * @return HasMany */ public function appearances(): HasMany { return $this->hasMany(Appearance::class); } /** * @return HasMany */ public function properties(): HasMany { return $this->hasMany(Property::class); } /** * The property sections show when they do not name one (the first active property). */ public function primaryProperty(): ?Property { return $this->properties()->where('is_active', true)->orderBy('id')->first() ?? Property::query()->where('is_active', true)->whereNull('site_id')->orderBy('id')->first(); } /** * The appearance in effect on $date: the active seasonal one with the highest priority, else the default. */ public function appearanceOn(CarbonInterface $date): ?Appearance { $appearances = $this->appearances()->where('is_active', true)->get(); return $appearances ->filter(fn (Appearance $appearance): bool => $appearance->covers($date)) ->sortByDesc('priority') ->first() ?? $appearances->firstWhere('is_default', true); } }