Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

3.0 KB
Raw Blame
<?php

declare(strict_types=1);

namespace HiEvents\Models;

use HiEvents\DomainObjects\Generated\EventDomainObjectAbstract;
use HiEvents\Models\Traits\HasImages;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;

class Event extends BaseModel
{
    use HasImages;
    use SoftDeletes;

    public function account(): BelongsTo
    {
        return $this->belongsTo(Account::class);
    }

    public function organizer(): BelongsTo
    {
        return $this->belongsTo(Organizer::class);
    }

    public function products(): HasMany
    {
        return $this->hasMany(Product::class)->orderBy('order');
    }

    public function product_categories(): HasMany
    {
        return $this->hasMany(ProductCategory::class)->orderBy('order');
    }

    public function attendees(): HasMany
    {
        return $this->hasMany(Attendee::class);
    }

    public function questions(): HasMany
    {
        return $this->hasMany(Question::class);
    }

    public function event_settings(): HasOne
    {
        return $this->hasOne(EventSetting::class);
    }

    public function promo_codes(): HasMany
    {
        return $this->hasMany(PromoCode::class);
    }

    public function check_in_lists(): HasMany
    {
        return $this->hasMany(CheckInList::class);
    }

    public function box_offices(): HasMany
    {
        return $this->hasMany(BoxOffice::class);
    }

    public function capacity_assignments(): HasMany
    {
        return $this->hasMany(CapacityAssignment::class);
    }

    public function event_statistics(): HasOne
    {
        return $this->hasOne(EventStatistic::class);
    }

    public function webhooks(): HasMany
    {
        return $this->hasMany(Webhook::class);
    }

    public function affiliates(): HasMany
    {
        return $this->hasMany(Affiliate::class);
    }

    public function event_lineup_entries(): HasMany
    {
        return $this->hasMany(EventLineupEntry::class);
    }

    public function event_spaces(): HasMany
    {
        return $this->hasMany(EventSpace::class);
    }

    public function event_schedule_items(): HasMany
    {
        return $this->hasMany(EventScheduleItem::class);
    }

    public function event_occurrences(): HasMany
    {
        return $this->hasMany(EventOccurrence::class);
    }

    public function event_location(): BelongsTo
    {
        return $this->belongsTo(EventLocation::class, 'event_location_id');
    }

    public static function boot(): void
    {
        parent::boot();

        static::creating(
            static function (Event $event) {
                $event->user_id = auth()->user()->id;
            }
        );
    }

    protected function getCastMap(): array
    {
        return [
            EventDomainObjectAbstract::ATTRIBUTES => 'array',
            EventDomainObjectAbstract::RECURRENCE_RULE => 'array',
        ];
    }
}