ldc-nature-eleveurs/database/factories/UserFactory.php

45 lines
1.3 KiB
PHP
Raw Normal View History

2022-08-09 12:29:21 +00:00
<?php
namespace Database\Factories;
2024-01-31 16:42:01 +01:00
use App\Enums\Users\RoleEnum;
2022-08-09 12:29:21 +00:00
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class UserFactory extends Factory
{
/**
* Define the model's default state.
*
2024-01-31 16:42:01 +01:00
* @return array<string, mixed>
2022-08-09 12:29:21 +00:00
*/
2024-01-31 16:42:01 +01:00
public function definition(): array
2022-08-09 12:29:21 +00:00
{
2024-01-31 16:42:01 +01:00
$published = $this->faker->boolean(75);
2022-08-09 12:29:21 +00:00
return [
2024-01-31 16:42:01 +01:00
'first_name' => fake()->firstname(),
'last_name' => fake()->lastname(),
'email' => fake()->unique()->safeEmail(),
2022-08-09 12:29:21 +00:00
'email_verified_at' => now(),
2024-01-31 16:42:01 +01:00
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
'remember_token' => Str::random(10),
'role' => \collect(RoleEnum::toArray())->random()->value,
'published' => $published,
'published_at' => ($published) ? now() : null,
2022-08-09 12:29:21 +00:00
];
}
/**
* Indicate that the model's email address should be unverified.
*
2024-01-31 16:42:01 +01:00
* @return static
2022-08-09 12:29:21 +00:00
*/
2024-01-31 16:42:01 +01:00
public function unverified(): static
2022-08-09 12:29:21 +00:00
{
2024-01-31 16:42:01 +01:00
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
2022-08-09 12:29:21 +00:00
}
}