PXG_2026_API/app/Console/Commands/SeedFlights.php

51 lines
1.5 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Event;
use App\Models\Flight;
class SeedFlights extends Command
{
protected $signature = 'pxg:seed-flights {--event=1}';
protected $description = 'Seed 72 flights for 2 courses (A/B) with 36 start points each (18 holes x 2 tees).';
public function handle(): int
{
$eventId = (int) $this->option('event');
$event = Event::find($eventId);
if (!$event) {
$this->error('Event not found: '.$eventId);
return 1;
}
// Create A01..A36 and B01..B36
$this->info('Seeding flights for event '.$eventId);
$courses = ['A','B'];
foreach ($courses as $course) {
$idx = 1;
for ($hole=1; $hole<=18; $hole++) {
foreach (['A','B'] as $tee) {
$code = $course . str_pad((string)$idx, 2, '0', STR_PAD_LEFT);
Flight::updateOrCreate(
['event_id' => $eventId, 'code' => $code],
[
'course' => $course,
'start_hole' => $hole,
'start_tee' => $tee,
'type' => 'NORMAL',
'status' => 'OPEN',
]
);
$idx++;
}
}
}
$this->info('Done.');
return 0;
}
}