auditionadmin/database/seeders/EntrySeeder.php

64 lines
3.1 KiB
PHP

<?php
namespace Database\Seeders;
use App\Models\Audition;
use App\Models\Entry;
use App\Models\Student;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use function rand;
use function random_int;
class EntrySeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$students = Student::all();
$hs_auditions = Audition::where('maximum_grade', '=', '12');
$freshman_auditions = Audition::where('maximum_grade', '>', '8');
$jh_auditions = Audition::where('maximum_grade', '=', '9');
$seventh_auditions = Audition::where('maximum_grade', '=', '7');
foreach ($students as $student) {
if($student->grade > 9) $audition = Audition::where('maximum_grade','=','12')->inRandomOrder()->first();
if($student->grade == 9) $audition = Audition::where('maximum_grade','>','8')->inRandomOrder()->first();
if($student->grade == 8) $audition = Audition::where('maximum_grade','=','9')->inRandomOrder()->first();
if($student->grade == 7) $audition = Audition::where('maximum_grade','=','7')->inRandomOrder()->first();
Entry::factory()->create([
'student_id' => $student->id,
'audition_id' => $audition->id
]);
if (random_int(1,100) > 80) {
if($student->grade > 9) $audition2 = Audition::where('maximum_grade','=','12')->where('id','!=',$audition->id)->inRandomOrder()->first();
if($student->grade == 9) $audition2 = Audition::where('maximum_grade','>','8')->where('id','!=',$audition->id)->inRandomOrder()->first();
if($student->grade == 8) $audition2 = Audition::where('maximum_grade','=','9')->where('id','!=',$audition->id)->inRandomOrder()->first();
if($student->grade == 7) $audition2 = Audition::where('maximum_grade','=','7')->where('id','!=',$audition->id)->inRandomOrder()->first();
Entry::factory()->create([
'student_id' => $student->id,
'audition_id' => $audition2->id
]);
}
if (random_int(1,100) > 80) {
if($student->grade > 9) $audition3 = Audition::where('maximum_grade','=','12')->where('id','!=',$audition->id)->where('id','!=',$audition2->id)->inRandomOrder()->first();
if($student->grade == 9) $audition3 = Audition::where('maximum_grade','>','8')->where('id','!=',$audition->id)->where('id','!=',$audition2->id)->inRandomOrder()->first();
if($student->grade == 8) $audition3 = Audition::where('maximum_grade','=','9')->where('id','!=',$audition->id)->where('id','!=',$audition2->id)->inRandomOrder()->first();
if($student->grade == 7) $audition3 = Audition::where('maximum_grade','=','7')->where('id','!=',$audition->id)->where('id','!=',$audition2->id)->inRandomOrder()->first();
Entry::factory()->create([
'student_id' => $student->id,
'audition_id' => $audition3->id
]);
}
}
}
}