first
This commit is contained in:
39
database/factories/DaerahMengundiFactory.php
Normal file
39
database/factories/DaerahMengundiFactory.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user