40 lines
1.0 KiB
PHP
40 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\BahagianPilihanraya;
|
|
use App\Models\DaerahMengundi;
|
|
use App\Models\Election;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends Factory<DaerahMengundi>
|
|
*/
|
|
class DaerahMengundiFactory extends Factory
|
|
{
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
$bahagian = BahagianPilihanraya::factory()->create();
|
|
|
|
return [
|
|
'election_id' => $bahagian->election_id,
|
|
'bahagian_pilihanraya_id' => $bahagian->id,
|
|
'code' => strtoupper(fake()->unique()->bothify('D##')),
|
|
'name' => 'Daerah Mengundi '.fake()->streetName(),
|
|
];
|
|
}
|
|
|
|
public function forElection(Election $election): static
|
|
{
|
|
return $this->state(fn () => [
|
|
'election_id' => $election->id,
|
|
'bahagian_pilihanraya_id' => BahagianPilihanraya::factory()->for($election)->create()->id,
|
|
]);
|
|
}
|
|
}
|