where('audition_id', $audition->id)->update(['draw_number' => null]); $randomizedEntries = $audition->entries->shuffle(); // Move entries flagged as no show to the end [$noShowEntries, $otherEntries] = $randomizedEntries->partition(function ($entry) { return $entry->hasFlag('no_show'); }); // Merge the entries, placing the 'no_show' entries at the end $randomizedEntries = $otherEntries->merge($noShowEntries); foreach ($randomizedEntries as $index => $entry) { $entry->draw_number = $index + 1; $entry->save(); } $audition->addFlag('drawn'); } public function runDrawsOnCollection($auditions): void { $auditions->each(fn ($audition) => $this->runOneDraw($audition)); } public function checkCollectionForDrawnAuditions($auditions): bool { $auditions->loadMissing('flags'); return $auditions->contains(fn ($audition) => $audition->hasFlag('drawn')); } public function clearDrawForAudition(Audition $audition): void { $audition->removeFlag('drawn'); DB::table('entries')->where('audition_id', $audition->id)->update(['draw_number' => null]); } public function clearDrawsOnCollection($auditions): void { $auditions->each(fn ($audition) => $this->clearDrawForAudition($audition)); } }