1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Database\Factories; |
4
|
|
|
|
5
|
|
|
use App\Enum\Gender; |
6
|
|
|
use App\Models\User; |
7
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory; |
8
|
|
|
use Illuminate\Support\Carbon; |
9
|
|
|
use Illuminate\Support\Str; |
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
|
|
|
* Define the model's default state. |
22
|
|
|
* |
23
|
|
|
* @return array |
24
|
|
|
*/ |
25
|
|
|
public function definition() |
26
|
|
|
{ |
27
|
|
|
$gender = $this->faker->randomElement(Gender::toValues()); |
28
|
|
|
|
29
|
|
|
return [ |
30
|
|
|
'username' => $this->faker->userName, |
31
|
|
|
'fullname' => $this->faker->name($gender), |
32
|
|
|
'gender' => $gender, |
33
|
|
|
'email' => $this->faker->unique()->safeEmail(), |
34
|
|
|
'phone_country' => env('PHONE_COUNTRY', 'ID'), |
35
|
|
|
'phone' => $this->faker->numerify('081#########'), |
36
|
|
|
'email_verified_at' => Carbon::now(), |
37
|
|
|
'password' => 'password', |
38
|
|
|
'remember_token' => Str::random(10), |
39
|
|
|
'is_active' => true, |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Indicate that the model's email address should be unverified. |
45
|
|
|
* |
46
|
|
|
* @return \Illuminate\Database\Eloquent\Factories\Factory |
47
|
|
|
*/ |
48
|
|
|
public function unverified() |
49
|
|
|
{ |
50
|
|
|
return $this->state(function (array $attributes) { |
|
|
|
|
51
|
|
|
return [ |
52
|
|
|
'email_verified_at' => null, |
53
|
|
|
]; |
54
|
|
|
}); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Indicate that the model's account should be unactivate. |
59
|
|
|
* |
60
|
|
|
* @return \Illuminate\Database\Eloquent\Factories\Factory |
61
|
|
|
*/ |
62
|
|
|
public function unactivate() |
63
|
|
|
{ |
64
|
|
|
return $this->state(function (array $attributes) { |
|
|
|
|
65
|
|
|
return [ |
66
|
|
|
'is_active' => false, |
67
|
|
|
]; |
68
|
|
|
}); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Indicate that the model's account should be activate. |
73
|
|
|
* |
74
|
|
|
* @return \Illuminate\Database\Eloquent\Factories\Factory |
75
|
|
|
*/ |
76
|
|
|
public function activate() |
77
|
|
|
{ |
78
|
|
|
return $this->state(function (array $attributes) { |
|
|
|
|
79
|
|
|
return [ |
80
|
|
|
'is_active' => true, |
81
|
|
|
]; |
82
|
|
|
}); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.