'Bild mit Link', 'text' => 'Text', 'notice' => 'Hinweis', ]; public const AREAS = [ 'aside' => 'Seitenleiste (rechts)', 'main' => 'Hauptspalte (breit)', 'top' => 'Ganz oben (volle Breite)', ]; public const VARIANTS = [ 'brand' => 'Markenfarbe', 'info' => 'Info (blau)', 'success' => 'Erfolg (grün)', 'warning' => 'Warnung (rot)', 'neutral' => 'Neutral (grau)', ]; protected static function booted(): void { static::saving(function (DashboardTile $tile) { $tile->url = filled($tile->url) ? (Field::safeUrl($tile->url) ?: null) : null; if ($tile->isDirty('body')) { $tile->body_html = app(RichText::class)->toSafeHtml($tile->body); } }); static::deleted(fn (DashboardTile $tile) => $tile->image_path && Storage::disk('uploads')->delete($tile->image_path)); } protected function casts(): array { return ['new_tab' => 'boolean', 'is_active' => 'boolean', 'starts_at' => 'datetime', 'ends_at' => 'datetime']; } public function widgetKey(): string { return 'tile.'.$this->id; } /** * Aktiv, im Zeitraum und für die Person sichtbar. * * @param Builder $query */ public function scopeVisibleTo(Builder $query, User $user): void { $query->where('is_active', true) ->where(fn ($q) => $q->whereNull('starts_at')->orWhere('starts_at', '<=', now())) ->where(fn ($q) => $q->whereNull('ends_at')->orWhere('ends_at', '>', now())); Audiences::constrain($query, 'dashboard_tile', 'dashboard_tiles.id', $user); } /** * @return array */ public function toWidgetProps(): array { return [ 'tile' => [ 'type' => $this->type, 'title' => $this->title, 'image_url' => $this->image_path ? Storage::disk('uploads')->url($this->image_path) : null, 'url' => $this->url, 'new_tab' => $this->new_tab, 'alt' => $this->alt ?: '', 'html' => $this->body_html, 'variant' => $this->variant ?: 'brand', ], ]; } }