forge/database/factories/UserFactory.php

57 lines
1.4 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-10 13:31:14 -04:00
use Random\RandomException;
2024-05-13 18:55:34 -04:00
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-09-11 14:15:13 -04:00
*
2024-09-10 13:31:14 -04:00
* @throws RandomException
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'),
2024-10-12 13:09:42 -06:00
// TODO: Does Faker have a markdown plugin?
2024-09-10 13:31:14 -04:00
'about' => fake()->paragraphs(random_int(1, 10), true),
2024-10-12 13:09:42 -06:00
2024-05-13 18:55:34 -04:00
'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,
]);
}
}