siakad-itm/database/factories/UserFactory.php
Yoga Pangestu 5cc8ba26b2
Some checks failed
tests / ci (pull_request) Has been cancelled
feat: update user registration to use username instead of name, add user profile model and migration, and implement gender enum
- Changed user creation to use 'username' instead of 'name'.
- Added UserProfile model with relationships to User and gender enum.
- Updated validation rules for username and email.
- Modified migrations to create user_profiles table and adjust users table.
- Updated seeder to create users with profiles.
- Translated various UI texts to Indonesian and improved layout components.
2026-08-03 13:43:30 +07:00

46 lines
1.2 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
/**
* @extends Factory<User>
*/
class UserFactory extends Factory
{
protected static ?string $password;
public function definition(): array
{
return [
'username' => fake()->unique()->userName(),
'email' => fake()->unique()->safeEmail(),
'password' => static::$password ??= Hash::make('password'),
'is_active' => true,
'last_login_at' => null,
'two_factor_secret' => null,
'two_factor_recovery_codes' => null,
'two_factor_confirmed_at' => null,
];
}
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
public function withTwoFactor(): static
{
return $this->state(fn (array $attributes) => [
'two_factor_secret' => encrypt('secret'),
'two_factor_recovery_codes' => encrypt(json_encode(['recovery-code-1'])),
'two_factor_confirmed_at' => now(),
]);
}
}