Work on Audition seeder

This commit is contained in:
Matt Young 2024-05-30 22:07:59 -05:00
parent acb2d64179
commit 33747e0658
4 changed files with 72 additions and 3 deletions

View File

@ -17,7 +17,7 @@ class EventFactory extends Factory
public function definition(): array
{
return [
//
'name' => 'Concert Band Auditions'
];
}
}

View File

@ -13,7 +13,7 @@ return new class extends Migration
{
Schema::create('events', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('name')->unique();
$table->timestamps();
});
}

View File

@ -15,10 +15,12 @@ return new class extends Migration
Schema::create('auditions', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(Event::class)->constrained()->cascadeOnUpdate()->restrictOnDelete();
$table->string('name');
$table->string('name')->unique();
$table->integer('order')->nullable()->unique();
$table->date(('entry_deadline'));
$table->integer('entry_fee');
$table->integer('minimum_grade');
$table->integer('maximum_grade');
$table->timestamps();
});
}

View File

@ -0,0 +1,67 @@
<?php
namespace Database\Seeders;
use App\Models\Event;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class AuditionSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$event = Event::factory()->create([
'name' => 'Concert Band Auditions'
]);
$instruments = [
'Flute',
'Oboe',
'Clarinet',
'Bass Clarinet',
'Contra Clarinet',
'Bassoon',
'Alto Sax',
'Tenor Sax',
'Bari Sax',
'Trumpet',
'Horn',
'Trombone',
'Euphonium',
'Tuba',
'String Bass',
'Percussion'
];
$levels = ['HS', 'JH', '7th'];
$n = 1;
foreach ($levels as $level) {
if ($level == 'HS') {
$minGrade = 9;
$maxGrade = 12;
}
if ($level == 'JH') {
$minGrade = 8;
$maxGrade = 9;
}if ($level == '7th') {
$minGrade = 7;
$maxGrade = 7;
}
foreach ($instruments as $instrument) {
DB::table('auditions')->insert([
'event_id' => $event->id,
'name' => $level . ' ' . $instrument,
'order' => $n,
'entry_deadline' => '2040-12-31',
'entry_fee' => '1000',
'minimum_grade' => $minGrade,
'maximum_grade' => $maxGrade
]);
$n++;
}
}
}
}