- Introduced Event and EventDate models with relationships to Tenant and CatalogItem. - Added active_event_id to Tenant model to track the currently active event. - Updated TenantResource to include active event details in the response. - Enhanced Ticket model to link to CatalogItem and Variant, allowing for event-specific ticketing. - Implemented migrations to create events and link them to catalog items and variants. - Updated seeders to populate events and their associated dates for the Fiesta Futbol Infantil tenant. - Modified Ticket generation logic to respect event dates over standard ticket dates. - Added tests for event and ticket functionalities, ensuring proper relationships and date handling.
56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Event\Models;
|
|
|
|
use App\Domains\Catalog\Models\Variant;
|
|
use Carbon\CarbonInterface;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
#[Fillable([
|
|
'event_id',
|
|
'date',
|
|
'time_start',
|
|
'time_end',
|
|
])]
|
|
class EventDate extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
public $timestamps = false;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'event_id' => 'integer',
|
|
'date' => 'date:Y-m-d',
|
|
];
|
|
}
|
|
|
|
/** @return BelongsTo<Event, $this> */
|
|
public function event(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Event::class);
|
|
}
|
|
|
|
/** @return HasMany<Variant, $this> */
|
|
public function variants(): HasMany
|
|
{
|
|
return $this->hasMany(Variant::class);
|
|
}
|
|
|
|
public function startsAt(): CarbonInterface
|
|
{
|
|
return Carbon::parse($this->date->format('Y-m-d').' '.$this->time_start);
|
|
}
|
|
|
|
public function endsAt(): CarbonInterface
|
|
{
|
|
return Carbon::parse($this->date->format('Y-m-d').' '.$this->time_end);
|
|
}
|
|
}
|