hypothetical/database/factories/UserFactory.php

45 lines
1 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
2024-01-12 22:03:27 -05:00
use Illuminate\Support\Facades\Hash;
2019-10-31 17:24:53 -04:00
use Illuminate\Support\Str;
2022-05-23 21:01:33 -04:00
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
*/
class UserFactory extends Factory
{
2024-01-12 22:03:27 -05:00
/**
* The current password being used by the factory.
*/
protected static ?string $password;
/**
* Define the model's default state.
*
2022-05-23 21:01:33 -04:00
* @return array<string, mixed>
*/
2023-03-13 17:33:19 -04:00
public function definition(): array
{
return [
2022-10-11 18:14:02 -04:00
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
2024-01-12 22:03:27 -05:00
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
];
}
2021-04-20 17:11:13 -04:00
/**
* Indicate that the model's email address should be unverified.
*/
2023-03-13 17:33:19 -04:00
public function unverified(): static
2021-04-20 17:11:13 -04:00
{
2022-10-11 18:14:02 -04:00
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
2021-04-20 17:11:13 -04:00
}
}