|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Database\Factories; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory; |
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
use Sfneal\Queries\RandomModelAttributeQuery; |
|
8
|
|
|
use Sfneal\Users\Models\Role; |
|
9
|
|
|
use Sfneal\Users\Models\User; |
|
10
|
|
|
|
|
11
|
|
|
class UserFactory extends Factory |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The name of the factory's corresponding model. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $model = User::class; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* UserFactory constructor. |
|
22
|
|
|
* |
|
23
|
|
|
* @param null $count |
|
|
|
|
|
|
24
|
|
|
* @param Collection|null $states |
|
25
|
|
|
* @param Collection|null $has |
|
26
|
|
|
* @param Collection|null $for |
|
27
|
|
|
* @param Collection|null $afterMaking |
|
28
|
|
|
* @param Collection|null $afterCreating |
|
29
|
|
|
* @param null $connection |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct($count = null, ?Collection $states = null, ?Collection $has = null, ?Collection $for = null, ?Collection $afterMaking = null, ?Collection $afterCreating = null, $connection = null) |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct($count, $states, $has, $for, $afterMaking, $afterCreating, $connection); |
|
34
|
|
|
|
|
35
|
|
|
// Create Role models if none exist |
|
36
|
|
|
self::createRoleFactories(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Define the model's default state. |
|
41
|
|
|
* |
|
42
|
|
|
* @return array |
|
43
|
|
|
*/ |
|
44
|
|
|
public function definition(): array |
|
45
|
|
|
{ |
|
46
|
|
|
return [ |
|
47
|
|
|
'role_id' => (new RandomModelAttributeQuery(Role::class, 'role_id'))->execute(), |
|
48
|
|
|
'first_name' => $this->faker->firstName, |
|
49
|
|
|
'middle_name' => $this->faker->randomElement([$this->faker->randomLetter, null]), |
|
50
|
|
|
'last_name' => $this->faker->lastName, |
|
51
|
|
|
'nickname' => $this->faker->randomElement([$this->faker->firstName]), |
|
52
|
|
|
'nickname_preferred' => $this->faker->numberBetween(0, 1), |
|
53
|
|
|
'title' => $this->faker->jobTitle, |
|
54
|
|
|
'suffix' => null, |
|
55
|
|
|
'email' => $this->faker->email, |
|
56
|
|
|
'rate' => $this->faker->numberBetween(20, 200), |
|
57
|
|
|
'phone_work' => $this->faker->phoneNumber, |
|
58
|
|
|
'phone_mobile' => $this->faker->phoneNumber, |
|
59
|
|
|
'fax' => $this->faker->phoneNumber, |
|
60
|
|
|
'website' => $this->faker->url, |
|
61
|
|
|
'bio' => $this->faker->text(255), |
|
62
|
|
|
'username' => $this->faker->userName, |
|
63
|
|
|
'password' => $this->faker->password, |
|
64
|
|
|
'status' => $this->faker->numberBetween(0, 1), |
|
65
|
|
|
'remember_token' => null, |
|
66
|
|
|
]; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Create Role model factories if none exist. |
|
71
|
|
|
* |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
|
|
private static function createRoleFactories(): void |
|
75
|
|
|
{ |
|
76
|
|
|
if (! Role::query()->count()) { |
|
|
|
|
|
|
77
|
|
|
Role::factory() |
|
78
|
|
|
->count(10) |
|
79
|
|
|
->create(); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|