69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Ticketing\Event\Models;
|
|
|
|
use App\Domains\Core\Tenant\Models\SocialMedia;
|
|
use App\Domains\Core\Tenant\Models\Tenant;
|
|
use App\Domains\Commerce\Catalog\Models\CatalogItem;
|
|
use App\Shared\Attachable\Models\Attachment;
|
|
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\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
#[Fillable(['tenant_code', 'event_category_id', 'title', 'subtitle', 'description', 'location', 'exact_location', 'date_text', 'published_at', 'attachment_id'])]
|
|
class Event extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['published_at' => 'datetime', 'exact_location' => 'array'];
|
|
}
|
|
|
|
/** @return BelongsTo<Tenant, $this> */
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class, 'tenant_code', 'codigo');
|
|
}
|
|
|
|
/** @return BelongsTo<EventCategory, $this> */
|
|
public function eventCategory(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EventCategory::class);
|
|
}
|
|
|
|
/** @return BelongsTo<Attachment, $this> */
|
|
public function attachment(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Attachment::class);
|
|
}
|
|
|
|
/** @return HasMany<EventDate, $this> */
|
|
public function dates(): HasMany
|
|
{
|
|
return $this->hasMany(EventDate::class)->orderBy('date')->orderBy('time_start');
|
|
}
|
|
|
|
/** @return HasMany<CatalogItem, $this> */
|
|
public function catalogItems(): HasMany
|
|
{
|
|
return $this->hasMany(CatalogItem::class)->whereAvailable()->orderBy('group_order')->orderBy('id');
|
|
}
|
|
|
|
/** @return BelongsToMany<SocialMedia, $this> */
|
|
public function socialMedia(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
SocialMedia::class,
|
|
'event_social_media',
|
|
'event_id',
|
|
'social_media_code',
|
|
'id',
|
|
'code',
|
|
)->withPivot(['url', 'orden'])->withTimestamps()->orderByPivot('orden');
|
|
}
|
|
}
|