66 lines
2.0 KiB
PHP
66 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\DrawSession;
|
|
use App\Models\Member;
|
|
use App\Models\Prize;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class DatabaseSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$this->call(RoleUserSeeder::class);
|
|
|
|
// Sesi cabutan aktif untuk event
|
|
DrawSession::firstOrCreate(
|
|
['is_active' => true],
|
|
['nama' => 'Mesyuarat Agung Tahunan KOIPB ' . date('Y')]
|
|
);
|
|
|
|
// 200 anggota dummy
|
|
if (Member::count() === 0) {
|
|
Member::factory()->count(200)->create();
|
|
}
|
|
|
|
$this->seedPrizes();
|
|
}
|
|
|
|
private function seedPrizes(): void
|
|
{
|
|
if (Prize::count() > 0) {
|
|
return;
|
|
}
|
|
|
|
// Definisi hadiah (kuantiti > 1 dipecah jadi item berasingan)
|
|
$definitions = [
|
|
['H01', 'Cabutan Utama - Umrah', 'Utama', 12000, 1, 1],
|
|
['H02', 'Motosikal', 'Utama', 6000, 2, 1],
|
|
['H03', 'Peti Sejuk 2 Pintu', 'Elektrik', 2500, 3, 1],
|
|
['H04', 'Mesin Basuh', 'Elektrik', 1800, 4, 1],
|
|
['H05', 'Smart TV 55"', 'Elektrik', 3200, 5, 1],
|
|
['H06', 'Telefon Pintar', 'Gajet', 2200, 6, 2],
|
|
['H07', 'Tablet', 'Gajet', 1500, 7, 2],
|
|
['H08', 'Basikal', 'Sukan', 900, 8, 2],
|
|
['H09', 'Hamper Premium', 'Hamper', 350, 9, 5],
|
|
['H10', 'Baucar Tunai RM200', 'Baucar', 200, 10, 5],
|
|
];
|
|
|
|
foreach ($definitions as [$kod, $nama, $kategori, $nilai, $drawOrder, $kuantiti]) {
|
|
for ($n = 1; $n <= $kuantiti; $n++) {
|
|
Prize::create([
|
|
'kod_hadiah' => $kod,
|
|
'nama_hadiah' => $kuantiti > 1 ? "{$nama} #{$n}" : $nama,
|
|
'kategori' => $kategori,
|
|
'nilai_anggaran' => $nilai,
|
|
'draw_order' => $drawOrder,
|
|
'item_index' => $n,
|
|
'batch_kod' => $kod,
|
|
'status' => Prize::STATUS_BELUM,
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|