94 lines
3.7 KiB
PHP
94 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use App\Models\Student;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
use function mt_rand;
|
|
|
|
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 (mt_rand(1, 100) > 90) {
|
|
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 (mt_rand(1, 100) > 90) {
|
|
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,
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|