62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Club;
|
|
use App\Models\Player;
|
|
use Illuminate\Database\Seeder;
|
|
use Database\Seeders\Traits\HasPlayerNames;
|
|
|
|
class PlayerSeeder extends Seeder
|
|
{
|
|
use HasPlayerNames;
|
|
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$this->command->info('Seeding players for each club with unique squad numbers and names...');
|
|
|
|
$clubs = Club::all();
|
|
$playerNames = $this->getPlayerNames();
|
|
$totalNames = count($playerNames);
|
|
$nameIndex = 0;
|
|
|
|
if ($clubs->isEmpty()) {
|
|
$this->command->warn('No clubs found. Skipping player seeding.');
|
|
return;
|
|
}
|
|
|
|
$this->command->getOutput()->progressStart($clubs->count());
|
|
|
|
foreach ($clubs as $club) {
|
|
$availableNumbers = range(1, 99);
|
|
shuffle($availableNumbers);
|
|
|
|
for ($i = 0; $i < 10; $i++) {
|
|
$squadNumber = array_pop($availableNumbers);
|
|
if (is_null($squadNumber)) {
|
|
break;
|
|
}
|
|
|
|
$name = $playerNames[$nameIndex % $totalNames];
|
|
$nameIndex++;
|
|
|
|
Player::create([
|
|
'club_id' => $club->id,
|
|
'squad_number' => $squadNumber,
|
|
'full_name_ru' => $name['ru'],
|
|
'full_name_en' => $name['en'],
|
|
'weight' => rand(65, 105),
|
|
'height' => rand(160, 210),
|
|
]);
|
|
}
|
|
$this->command->getOutput()->progressAdvance();
|
|
}
|
|
|
|
$this->command->getOutput()->progressFinish();
|
|
$this->command->info("\nFinished seeding players.");
|
|
}
|
|
}
|