1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use Illuminate\Auth\Authenticatable; |
7
|
|
|
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
8
|
|
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
9
|
|
|
use Illuminate\Database\Eloquent\Collection; |
10
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo; |
11
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany; |
12
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
13
|
|
|
use Laravel\Lumen\Auth\Authorizable; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class User |
17
|
|
|
* |
18
|
|
|
* @property int $id |
19
|
|
|
* @property string|null $name |
20
|
|
|
* @property string|null $email |
21
|
|
|
* @property string|null $password |
22
|
|
|
* @property string|null $picture |
23
|
|
|
* @property int $status |
24
|
|
|
* @property int $language_id |
25
|
|
|
* @property int $role_id |
26
|
|
|
* @property string|null $activation_code |
27
|
|
|
* @property string|null $forgot_code |
28
|
|
|
* @property Carbon|null $forgot_time |
29
|
|
|
* @property string|null $facebook_id |
30
|
|
|
* @property string|null $google_id |
31
|
|
|
* @property Carbon|null $created_at |
32
|
|
|
* @property Carbon|null $updated_at |
33
|
|
|
* @property Carbon|null $deleted_at |
34
|
|
|
* |
35
|
|
|
* @property-read Collection|UserToken[] $userTokens |
36
|
|
|
* @property-read Collection|UserNotification[] $userNotifications |
37
|
|
|
* @property-read Language $language |
38
|
|
|
* @property-read Role $role |
39
|
|
|
* @property-read Collection|UserTask[] $userTasks |
40
|
|
|
* @property-read Collection|UserTask[] $userAssignedTasks |
41
|
|
|
* |
42
|
|
|
* @package App\Models |
43
|
|
|
*/ |
44
|
|
|
class User extends Model implements AuthenticatableContract, AuthorizableContract |
45
|
|
|
{ |
46
|
|
|
use Authenticatable, Authorizable, SoftDeletes; |
47
|
|
|
|
48
|
|
|
/** @var int */ |
49
|
|
|
const STATUS_UNCONFIRMED = 0; |
50
|
|
|
|
51
|
|
|
/** @var int */ |
52
|
|
|
const STATUS_CONFIRMED = 1; |
53
|
|
|
|
54
|
|
|
/** @var int */ |
55
|
|
|
const STATUS_EMAIL_UNCONFIRMED = 2; |
56
|
|
|
|
57
|
|
|
/** @var bool */ |
58
|
|
|
public $timestamps = true; |
59
|
|
|
|
60
|
|
|
/** @var string */ |
61
|
|
|
protected $table = 'users'; |
62
|
|
|
|
63
|
|
|
/** @var array */ |
64
|
|
|
protected $fillable = [ |
65
|
|
|
'name', |
66
|
|
|
'email', |
67
|
|
|
'password', |
68
|
|
|
'picture', |
69
|
|
|
'status', |
70
|
|
|
'language_id', |
71
|
|
|
'role_id', |
72
|
|
|
'activation_code', |
73
|
|
|
'forgot_code', |
74
|
|
|
'forgot_time', |
75
|
|
|
'facebook_id', |
76
|
|
|
'google_id' |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
/** @var array */ |
80
|
|
|
protected $hidden = [ |
81
|
|
|
'password', |
82
|
|
|
'activation_code', |
83
|
|
|
'forgot_code', |
84
|
|
|
'forgot_time', |
85
|
|
|
'facebook_id', |
86
|
|
|
'google_id' |
87
|
|
|
]; |
88
|
|
|
|
89
|
|
|
/** @var array */ |
90
|
|
|
protected $visible = [ |
91
|
|
|
'id', |
92
|
|
|
'name', |
93
|
|
|
'email', |
94
|
|
|
'picture', |
95
|
|
|
'status', |
96
|
|
|
'language_id', |
97
|
|
|
'role_id', |
98
|
|
|
'created_at', |
99
|
|
|
'updated_at', |
100
|
|
|
'language', |
101
|
|
|
'role', |
102
|
|
|
'userNotifications', |
103
|
|
|
'userTasks', |
104
|
|
|
'userAssignedTasks' |
105
|
|
|
]; |
106
|
|
|
|
107
|
|
|
/** @var array */ |
108
|
|
|
protected $casts = [ |
109
|
|
|
'status' => 'int' |
110
|
|
|
]; |
111
|
|
|
|
112
|
|
|
/** @var array */ |
113
|
|
|
protected $sortable = [ |
114
|
|
|
'id', |
115
|
|
|
'name', |
116
|
|
|
'email', |
117
|
|
|
'status', |
118
|
|
|
'created_at', |
119
|
|
|
'updated_at', |
120
|
|
|
]; |
121
|
|
|
|
122
|
|
|
/** @var array */ |
123
|
|
|
protected $searchable = [ |
124
|
|
|
'name', |
125
|
|
|
'email' |
126
|
|
|
]; |
127
|
|
|
|
128
|
|
|
/** @var array */ |
129
|
|
|
protected $encrypted = [ |
130
|
|
|
'name', |
131
|
|
|
'email' |
132
|
|
|
]; |
133
|
|
|
|
134
|
|
|
/** @var array */ |
135
|
|
|
protected $filterable = [ |
136
|
|
|
'status', |
137
|
|
|
'language_id', |
138
|
|
|
'role_id' |
139
|
|
|
]; |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* User tokens. |
143
|
|
|
* |
144
|
|
|
* @return HasMany |
145
|
|
|
*/ |
146
|
|
|
public function userTokens() |
147
|
|
|
{ |
148
|
|
|
return $this->hasMany(UserToken::class, 'user_id', 'id'); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* User notifications. |
153
|
|
|
* |
154
|
|
|
* @return HasMany |
155
|
|
|
*/ |
156
|
|
|
public function userNotifications() |
157
|
|
|
{ |
158
|
|
|
return $this->hasMany(UserNotification::class, 'user_id', 'id'); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Language. |
163
|
|
|
* |
164
|
|
|
* @return BelongsTo |
165
|
|
|
*/ |
166
|
|
|
public function language() |
167
|
|
|
{ |
168
|
|
|
return $this->belongsTo(Language::class, 'language_id', 'id'); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Role. |
173
|
|
|
* |
174
|
|
|
* @return BelongsTo |
175
|
|
|
*/ |
176
|
|
|
public function role() |
177
|
|
|
{ |
178
|
|
|
return $this->belongsTo(Role::class, 'role_id', 'id'); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* User tasks. |
183
|
|
|
* |
184
|
|
|
* @return HasMany |
185
|
|
|
*/ |
186
|
|
|
public function userTasks() |
187
|
|
|
{ |
188
|
|
|
return $this->hasMany(UserTask::class, 'user_id', 'id'); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* User assigned tasks. |
193
|
|
|
* |
194
|
|
|
* @return HasMany |
195
|
|
|
*/ |
196
|
|
|
public function userAssignedTasks() |
197
|
|
|
{ |
198
|
|
|
return $this->hasMany(UserTask::class, 'assigned_user_id', 'id'); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @param $value |
203
|
|
|
* |
204
|
|
|
* @return Carbon|null |
205
|
|
|
*/ |
206
|
|
|
public function getForgotTimeAttribute($value) |
207
|
|
|
{ |
208
|
|
|
if ($value !== null) { |
209
|
|
|
return Carbon::parse($value); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
return null; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param $value |
217
|
|
|
* |
218
|
|
|
* @return array|null |
219
|
|
|
*/ |
220
|
|
|
public function getPictureAttribute($value) |
221
|
|
|
{ |
222
|
|
|
if ($value !== null && $value !== '') { |
223
|
|
|
return json_decode($value, true); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
return null; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|