84 lines
1.9 KiB
PHP
84 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
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;
|
|
|
|
class Event extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'events';
|
|
protected $guarded = [];
|
|
protected $casts = [
|
|
'date' => 'datetime',
|
|
'settings' => 'array',
|
|
'is_active' => 'boolean',
|
|
'name' => 'array',
|
|
'description' => 'array',
|
|
];
|
|
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
public function eventType(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EventType::class);
|
|
}
|
|
|
|
public function photos(): HasMany
|
|
{
|
|
return $this->hasMany(Photo::class);
|
|
}
|
|
|
|
public function taskCollections(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
TaskCollection::class,
|
|
'event_task_collection',
|
|
'event_id',
|
|
'task_collection_id'
|
|
);
|
|
}
|
|
|
|
public function tasks(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Task::class, 'event_task', 'event_id', 'task_id')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function eventPackage(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EventPackage::class);
|
|
}
|
|
|
|
public function hasActivePackage(): bool
|
|
{
|
|
return $this->eventPackage && $this->eventPackage->isActive();
|
|
}
|
|
|
|
public function getPackageLimits(): array
|
|
{
|
|
if (!$this->hasActivePackage()) {
|
|
return [];
|
|
}
|
|
|
|
return $this->eventPackage->package->limits;
|
|
}
|
|
|
|
public function canUploadPhoto(): bool
|
|
{
|
|
if (!$this->hasActivePackage()) {
|
|
return false;
|
|
}
|
|
|
|
return $this->eventPackage->canUploadPhoto();
|
|
}
|
|
}
|