Files
crewli/api/app/Models/CrowdList.php

68 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use App\Enums\CrowdListType;
use App\Models\Scopes\OrganisationScope;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
final class CrowdList extends Model
{
use HasFactory;
use HasUlids;
/** @var string Used by OrganisationScope to determine filtering strategy */
public string $organisationScopeColumn = 'event_id';
protected static function booted(): void
{
static::addGlobalScope(new OrganisationScope());
}
protected $fillable = [
'event_id',
'crowd_type_id',
'name',
'type',
'recipient_company_id',
'auto_approve',
'max_persons',
];
protected function casts(): array
{
return [
'type' => CrowdListType::class,
'auto_approve' => 'boolean',
'max_persons' => 'integer',
];
}
public function event(): BelongsTo
{
return $this->belongsTo(Event::class);
}
public function crowdType(): BelongsTo
{
return $this->belongsTo(CrowdType::class);
}
public function recipientCompany(): BelongsTo
{
return $this->belongsTo(Company::class, 'recipient_company_id');
}
public function persons(): BelongsToMany
{
return $this->belongsToMany(Person::class, 'crowd_list_persons')
->withPivot('added_at', 'added_by_user_id');
}
}