2026-04-03 04:34:21 +07:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace Database\Seeders;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
|
|
|
|
|
|
class UserSeeder extends Seeder
|
|
|
|
|
|
{
|
|
|
|
|
|
public function run(): void
|
|
|
|
|
|
{
|
2026-04-05 22:35:53 +07:00
|
|
|
|
$divisions = \App\Models\Division::all();
|
2026-04-04 12:56:13 +07:00
|
|
|
|
|
2026-04-05 22:35:53 +07:00
|
|
|
|
// super_admin (tanpa divisi)
|
2026-04-04 12:56:13 +07:00
|
|
|
|
User::factory()->createOne([
|
|
|
|
|
|
'name' => 'Super Admin',
|
|
|
|
|
|
'email' => 'admin@admin.com',
|
|
|
|
|
|
'password' => bcrypt('admin'),
|
|
|
|
|
|
'phone' => '08123456789',
|
|
|
|
|
|
'status' => 'aktif',
|
|
|
|
|
|
])->assignRole('super_admin');
|
|
|
|
|
|
|
2026-04-05 22:35:53 +07:00
|
|
|
|
// ketua, bendahara, auditor — tanpa divisi spesifik
|
|
|
|
|
|
foreach (['ketua', 'bendahara', 'auditor'] as $role) {
|
|
|
|
|
|
User::factory(2)->create()->each(fn ($u) => $u->assignRole($role));
|
2026-04-03 04:34:21 +07:00
|
|
|
|
}
|
2026-04-04 12:56:13 +07:00
|
|
|
|
|
2026-04-05 06:21:16 +07:00
|
|
|
|
// 1 editor
|
|
|
|
|
|
User::factory()->createOne([
|
2026-04-05 22:35:53 +07:00
|
|
|
|
'name' => 'Editor Konten',
|
|
|
|
|
|
'email' => 'editor@persegi.test',
|
|
|
|
|
|
'password' => bcrypt('password'),
|
|
|
|
|
|
'status' => 'aktif',
|
2026-04-05 06:21:16 +07:00
|
|
|
|
])->assignRole('editor');
|
|
|
|
|
|
|
2026-04-05 22:35:53 +07:00
|
|
|
|
// Setiap divisi: 1 pengurus (jadi leader) + 3–8 anggota
|
|
|
|
|
|
foreach ($divisions as $division) {
|
|
|
|
|
|
$pengurus = User::factory()->create(['division_id' => $division->id]);
|
|
|
|
|
|
$pengurus->assignRole('pengurus');
|
|
|
|
|
|
|
|
|
|
|
|
$division->update(['leader_id' => $pengurus->id]);
|
|
|
|
|
|
|
|
|
|
|
|
$count = rand(3, 8);
|
|
|
|
|
|
User::factory($count)->create(['division_id' => $division->id])
|
|
|
|
|
|
->each(fn ($u) => $u->assignRole('anggota'));
|
|
|
|
|
|
}
|
2026-04-03 04:34:21 +07:00
|
|
|
|
}
|
|
|
|
|
|
}
|