hasMany(Audition::class)->orderBy('order_in_room'); } public function entries(): HasManyThrough { return $this->hasManyThrough( Entry::class, Audition::class, 'room_id', // Foreign key on the auditions table 'audition_id', //Foreign key on the Entries table 'id', // Local key on the rooms table 'id' // Local key on the Auditions table ); } public function users(): BelongsToMany { return $this->belongsToMany(User::class, 'room_user'); } public function judges(): BelongsToMany { return $this->belongsToMany(User::class, 'room_user', 'room_id', 'user_id'); } public function addJudge($userId): void { $this->judges()->attach($userId); $this->load('judges'); AuditionChange::dispatch(); } public function removeJudge($userId): void { $this->judges()->detach($userId); $this->load('judges'); AuditionChange::dispatch(); } }