57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
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\Database\Eloquent\Relations\HasManyThrough;
|
|
|
|
class Ensemble extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
public function event(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Event::class);
|
|
}
|
|
|
|
public function auditions(): HasManyThrough
|
|
{
|
|
return $this->hasManyThrough(
|
|
Audition::class,
|
|
Event::class,
|
|
'id',
|
|
'event_id',
|
|
'event_id',
|
|
'id'
|
|
)->orderBy('score_order');
|
|
}
|
|
|
|
public function seatingLimits(): HasMany
|
|
{
|
|
return $this->hasMany(SeatingLimit::class);
|
|
}
|
|
|
|
public function seats(): HasMany
|
|
{
|
|
return $this->hasMany(Seat::class);
|
|
}
|
|
|
|
public function scopeForAudition(Builder $query, $audition_id): Builder
|
|
{
|
|
$audition = Audition::find($audition_id);
|
|
// get instances of this class where the event_id is equal to the event_id of the audition with $audition_id
|
|
return $query->where('event_id', $audition->event_id);
|
|
}
|
|
|
|
public function scopeForEvent(Builder $query, $event_id): Builder
|
|
{
|
|
return $query->where('event_id', $event_id);
|
|
}
|
|
}
|