Files
persegi/database/seeders/UserSeeder.php
T

49 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Seeder;
class UserSeeder extends Seeder
{
public function run(): void
{
$divisions = \App\Models\Division::all();
// super_admin (tanpa divisi)
User::factory()->createOne([
'name' => 'Super Admin',
'email' => 'admin@admin.com',
'password' => bcrypt('admin'),
'phone' => '08123456789',
'status' => 'aktif',
])->assignRole('super_admin');
// ketua, bendahara, auditor — tanpa divisi spesifik
foreach (['ketua', 'bendahara', 'auditor'] as $role) {
User::factory(2)->create()->each(fn ($u) => $u->assignRole($role));
}
// 1 editor
User::factory()->createOne([
'name' => 'Editor Konten',
'email' => 'editor@persegi.test',
'password' => bcrypt('password'),
'status' => 'aktif',
])->assignRole('editor');
// Setiap divisi: 1 pengurus (jadi leader) + 38 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'));
}
}
}