forge/database/factories/UserFactory.php

50 lines
1.2 KiB
PHP
Raw Normal View History

2024-05-13 18:55:34 -04:00
<?php
namespace Database\Factories;
2024-09-11 23:08:58 -04:00
use App\Models\User;
2024-05-13 18:55:34 -04:00
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
2024-09-11 23:08:58 -04:00
/**
* @extends Factory<User>
*/
2024-05-13 18:55:34 -04:00
class UserFactory extends Factory
{
/**
* The current password being used by the factory.
*/
protected static ?string $password;
2024-09-11 23:08:58 -04:00
protected $model = User::class;
2024-05-13 18:55:34 -04:00
/**
* Define the user's default state.
2024-05-13 18:55:34 -04:00
*/
public function definition(): array
{
return [
'name' => fake()->userName(),
2024-05-13 18:55:34 -04:00
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'two_factor_secret' => null,
'two_factor_recovery_codes' => null,
'remember_token' => Str::random(10),
'user_role_id' => null,
2024-05-13 18:55:34 -04:00
'profile_photo_path' => null,
];
}
/**
* Indicate that the user's email address should be unverified.
2024-05-13 18:55:34 -04:00
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}