44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Str;
|
|
|
|
/** @extends Factory<User> */
|
|
class UserFactory extends Factory
|
|
{
|
|
protected static ?string $password;
|
|
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'name' => fake()->name(),
|
|
'email' => fake()->unique()->safeEmail(),
|
|
'email_verified_at' => now(),
|
|
'password' => static::$password ??= Hash::make('password'),
|
|
'role' => 'user',
|
|
'department_id' => null,
|
|
'is_active' => true,
|
|
'remember_token' => Str::random(10),
|
|
];
|
|
}
|
|
|
|
public function admin(): static
|
|
{
|
|
return $this->state(fn () => ['role' => 'admin']);
|
|
}
|
|
|
|
public function inactive(): static
|
|
{
|
|
return $this->state(fn () => ['is_active' => false]);
|
|
}
|
|
|
|
public function unverified(): static
|
|
{
|
|
return $this->state(fn () => ['email_verified_at' => null]);
|
|
}
|
|
}
|