68 lines
2.0 KiB
PHP
68 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Str;
|
|
use App\Models\Rank;
|
|
use App\Models\Role;
|
|
use App\Models\User;
|
|
|
|
class UserSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$adminRole = Role::where(column: 'name', operator: 'ROLE_ADMIN')->first();
|
|
$userRole = Role::where(column: 'name', operator: 'ROLE_USER')->first();
|
|
$operatorRank = Rank::where('name', 'Operator')->first();
|
|
$memberRank = Rank::where('name', 'Member')->first();
|
|
|
|
$admin = User::updateOrCreate(
|
|
attributes: ['email' => 'tracer@24unix.net'],
|
|
values : [
|
|
'name' => 'tracer',
|
|
'name_canonical' => Str::lower('tracer'),
|
|
'rank_id' => $operatorRank?->id ?? $memberRank?->id,
|
|
'password' => Hash::make(value: 'password'),
|
|
'email_verified_at' => now(),
|
|
]
|
|
);
|
|
|
|
$micha = User::updateOrCreate(
|
|
attributes: ['email' => 'micha@24unix.net'],
|
|
values : [
|
|
'name' => 'Micha',
|
|
'name_canonical' => Str::lower('Micha'),
|
|
'rank_id' => $memberRank?->id,
|
|
'password' => Hash::make(value: 'password'),
|
|
'email_verified_at' => now(),
|
|
]
|
|
);
|
|
|
|
if ($adminRole) {
|
|
$admin->roles()->syncWithoutDetaching([$adminRole->id]);
|
|
}
|
|
|
|
if ($userRole) {
|
|
$admin->roles()->syncWithoutDetaching([$userRole->id]);
|
|
}
|
|
|
|
if ($userRole) {
|
|
$micha->roles()->syncWithoutDetaching([$userRole->id]);
|
|
}
|
|
|
|
$users = User::factory()->count(100)->create([
|
|
'email_verified_at' => now(),
|
|
]);
|
|
if ($userRole) {
|
|
foreach ($users as $user) {
|
|
$user->roles()->syncWithoutDetaching([$userRole->id]);
|
|
}
|
|
}
|
|
}
|
|
}
|