ldc-legaulois/database/factories/UserFactory.php

45 lines
1.3 KiB
PHP
Raw Normal View History

2020-07-23 10:29:36 +02:00
<?php
2021-10-22 10:52:32 +02:00
namespace Database\Factories;
2020-07-23 10:29:36 +02:00
2021-10-22 10:52:32 +02:00
use Illuminate\Database\Eloquent\Factories\Factory;
2024-01-10 14:49:46 +01:00
use Illuminate\Support\Str;
2020-07-23 10:29:36 +02:00
2021-10-22 10:52:32 +02:00
class UserFactory extends Factory
{
/**
* Define the model's default state.
*
2024-01-10 14:49:46 +01:00
* @return array<string, mixed>
2021-10-22 10:52:32 +02:00
*/
2024-01-10 14:49:46 +01:00
public function definition(): array
2021-10-22 10:52:32 +02:00
{
2024-01-10 14:49:46 +01:00
$published = $this->faker->boolean(75);
2024-04-04 14:19:53 +02:00
/** @var \App\Enums\Users\RoleEnum */
$randEnum = \collect(\App\Enums\Users\RoleEnum::toArray())->random();
2021-10-22 10:52:32 +02:00
return [
2024-04-04 14:19:53 +02:00
'first_name' => fake()->firstName,
'last_name' => fake()->lastName,
2024-01-10 14:49:46 +01:00
'email' => fake()->unique()->safeEmail(),
2021-10-22 10:52:32 +02:00
'email_verified_at' => now(),
2024-01-10 14:49:46 +01:00
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
'remember_token' => Str::random(10),
2024-04-04 14:19:53 +02:00
'role' => $randEnum->value,
2024-01-10 14:49:46 +01:00
'published' => $published,
'published_at' => ($published) ? now() : null,
2021-10-22 10:52:32 +02:00
];
}
2024-01-10 14:49:46 +01:00
/**
* Indicate that the model's email address should be unverified.
*
* @return static
*/
public function unverified(): static
{
return $this->state(fn () => [
2024-01-10 14:49:46 +01:00
'email_verified_at' => null,
]);
}
2021-10-22 10:52:32 +02:00
}