1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Database\Factories; |
4
|
|
|
|
5
|
|
|
use App\Models\Role; |
6
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory; |
7
|
|
|
use Illuminate\Support\Arr; |
8
|
|
|
use Illuminate\Support\Carbon; |
9
|
|
|
use Illuminate\Support\Str; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @see \App\Models\User |
13
|
|
|
*/ |
14
|
|
|
class UserFactory extends Factory |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritDoc} |
18
|
|
|
*/ |
19
|
|
|
public function definition() |
20
|
|
|
{ |
21
|
|
|
return [ |
22
|
|
|
'username' => $this->faker->userName(), |
23
|
|
|
'name' => $this->faker->name(), |
24
|
|
|
'email' => $this->faker->unique()->safeEmail(), |
25
|
|
|
'password' => 'password', |
26
|
|
|
'remember_token' => Str::random(10), |
27
|
|
|
]; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Indicate that the model's email address should be unverified. |
32
|
|
|
* |
33
|
|
|
* @return \Illuminate\Database\Eloquent\Factories\Factory |
34
|
|
|
*/ |
35
|
|
|
public function unverified() |
36
|
|
|
{ |
37
|
|
|
return $this->state(function (array $attributes) { |
38
|
|
|
return [ |
39
|
|
|
'email_verified_at' => null, |
40
|
|
|
]; |
41
|
|
|
}); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Indicate that the model's email address should be verified. |
46
|
|
|
* |
47
|
|
|
* @return \Illuminate\Database\Eloquent\Factories\Factory |
48
|
|
|
*/ |
49
|
|
|
public function verified() |
50
|
|
|
{ |
51
|
|
|
return $this->state(function (array $attributes) { |
52
|
|
|
return [ |
53
|
|
|
'email_verified_at' => Carbon::now(), |
54
|
|
|
]; |
55
|
|
|
}); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get the raw attributes generated by the factory for form purposes. |
60
|
|
|
* |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function rawForm(): array |
64
|
|
|
{ |
65
|
|
|
$data = $this->raw(); |
66
|
|
|
|
67
|
|
|
return array_merge($data, [ |
68
|
|
|
'password_confirmation' => $data['password'], |
69
|
|
|
'role' => Arr::random([Role::ROLE_MANAGER, Role::ROLE_STAFF]), |
70
|
|
|
]); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|