chore: update UserSeeder agar tiap divisi punya 1 pengurus (leader) dan 3-8 anggota
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use App\Models\Division;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
@@ -10,9 +9,9 @@ class UserSeeder extends Seeder
|
|||||||
{
|
{
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$divisions = Division::pluck('id')->toArray();
|
$divisions = \App\Models\Division::all();
|
||||||
|
|
||||||
// super_admin
|
// super_admin (tanpa divisi)
|
||||||
User::factory()->createOne([
|
User::factory()->createOne([
|
||||||
'name' => 'Super Admin',
|
'name' => 'Super Admin',
|
||||||
'email' => 'admin@admin.com',
|
'email' => 'admin@admin.com',
|
||||||
@@ -21,22 +20,29 @@ class UserSeeder extends Seeder
|
|||||||
'status' => 'aktif',
|
'status' => 'aktif',
|
||||||
])->assignRole('super_admin');
|
])->assignRole('super_admin');
|
||||||
|
|
||||||
// 2 user per role
|
// ketua, bendahara, auditor — tanpa divisi spesifik
|
||||||
foreach (['ketua', 'bendahara', 'pengurus', 'auditor', 'anggota'] as $role) {
|
foreach (['ketua', 'bendahara', 'auditor'] as $role) {
|
||||||
User::factory(2)->create(['division_id' => fake()->randomElement($divisions)])
|
User::factory(2)->create()->each(fn ($u) => $u->assignRole($role));
|
||||||
->each(fn ($user) => $user->assignRole($role));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1 editor
|
// 1 editor
|
||||||
User::factory()->createOne([
|
User::factory()->createOne([
|
||||||
'name' => 'Editor Konten',
|
'name' => 'Editor Konten',
|
||||||
'email' => 'editor@persegi.test',
|
'email' => 'editor@persegi.test',
|
||||||
'password' => bcrypt('password'),
|
'password' => bcrypt('password'),
|
||||||
'status' => 'aktif',
|
'status' => 'aktif',
|
||||||
'division_id' => fake()->randomElement($divisions),
|
|
||||||
])->assignRole('editor');
|
])->assignRole('editor');
|
||||||
|
|
||||||
// 2 user tanpa role
|
// Setiap divisi: 1 pengurus (jadi leader) + 3–8 anggota
|
||||||
User::factory(2)->create(['division_id' => fake()->randomElement($divisions)]);
|
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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user