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