'integer', 'event_date_id' => 'integer', 'inventory_id' => 'integer', 'minimum_use_date' => 'datetime', 'maximum_use_date' => 'datetime', ]; } /** @return BelongsTo */ public function catalogItem(): BelongsTo { return $this->belongsTo(CatalogItem::class); } /** @return BelongsTo */ public function eventDate(): BelongsTo { return $this->belongsTo(EventDate::class); } /** @return HasMany */ public function sourceTickets(): HasMany { return $this->hasMany(Ticket::class, 'source_variant_id'); } /** @return BelongsTo */ public function inventory(): BelongsTo { return $this->belongsTo(Inventory::class); } /** @return HasMany */ public function definitions(): HasMany { return $this->hasMany(VariantDefinition::class); } /** @return BelongsToMany */ public function attachments(): BelongsToMany { $relation = $this->belongsToMany( Attachment::class, 'catalog_items_attachments', 'variant_id', 'attachment_id' ) ->withPivot('orden') ->orderByPivot('orden'); if ($this->catalog_item_id !== null) { $relation->withPivotValue('catalog_item_id', $this->catalog_item_id); } return $relation; } public function getPrice(): float { return $this->catalogItem->getPrice(); } public function getName(): string { $name = $this->catalogItem->nombre; $this->loadMissing(['definitions.itemAttribute.attribute', 'eventDate']); $definitions = $this->definitions ->map(function (VariantDefinition $definition): ?string { $attributeName = $definition->itemAttribute?->attribute?->nombre; return $attributeName ? "{$attributeName}: {$definition->value}" : $definition->value; }) ->filter(); if ($this->eventDate !== null) { $definitions->push('Fecha: '.$this->eventDate->date->format('Y-m-d')); } $description = $definitions->implode(', '); return $description === '' ? $name : "{$name} ({$description})"; } public function getMinimumUseDate(): ?CarbonInterface { return $this->eventDate?->startsAt() ?? $this->minimum_use_date ?? $this->catalogItem->getMinimumUseDate(); } public function getMaximumUseDate(): ?CarbonInterface { return $this->eventDate?->endsAt() ?? $this->maximum_use_date ?? $this->catalogItem->getMaximumUseDate(); } }