51 lines
1.2 KiB
PHP
51 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
|
|
{
|
|
/**
|
|
* The current password being used by the factory.
|
|
*/
|
|
protected static ?string $password;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'username' => fake()->userName(),
|
|
'email' => fake()->unique()->safeEmail(),
|
|
'password' => static::$password ??= Hash::make('password'),
|
|
'is_active' => true,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Configure the model factory.
|
|
*/
|
|
public function configure(): static
|
|
{
|
|
return $this->afterCreating(function (User $user) {
|
|
$user->profile()->create([
|
|
'nik' => fake()->numerify('################'),
|
|
'full_name' => fake()->name(),
|
|
'phone_number' => fake()->phoneNumber(),
|
|
'address' => fake()->address(),
|
|
'birth_place' => fake()->city(),
|
|
'birth_date' => fake()->date(),
|
|
]);
|
|
});
|
|
}
|
|
}
|