LaravelTest
44 строки · 1.0 Кб
1<?php
2
3namespace Database\Factories;
4
5use Illuminate\Database\Eloquent\Factories\Factory;
6use Illuminate\Support\Facades\Hash;
7use Illuminate\Support\Str;
8
9/**
10* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
11*/
12class UserFactory extends Factory
13{
14/**
15* The current password being used by the factory.
16*/
17protected static ?string $password;
18
19/**
20* Define the model's default state.
21*
22* @return array<string, mixed>
23*/
24public function definition(): array
25{
26return [
27'name' => fake()->name(),
28'email' => fake()->unique()->safeEmail(),
29'email_verified_at' => now(),
30'password' => static::$password ??= Hash::make('password'),
31'remember_token' => Str::random(10),
32];
33}
34
35/**
36* Indicate that the model's email address should be unverified.
37*/
38public function unverified(): static
39{
40return $this->state(fn (array $attributes) => [
41'email_verified_at' => null,
42]);
43}
44}
45