1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Auth\Authenticatable; |
6
|
|
|
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
7
|
|
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
8
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo; |
9
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany; |
10
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
11
|
|
|
use Laravel\Lumen\Auth\Authorizable; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class User |
15
|
|
|
* |
16
|
|
|
* @package App\Models |
17
|
|
|
*/ |
18
|
|
|
class User extends Model implements AuthenticatableContract, AuthorizableContract |
19
|
|
|
{ |
20
|
|
|
use Authenticatable, Authorizable, SoftDeletes; |
|
|
|
|
21
|
|
|
|
22
|
|
|
/** @var int */ |
23
|
|
|
const STATUS_UNCONFIRMED = 0; |
24
|
|
|
|
25
|
|
|
/** @var int */ |
26
|
|
|
const STATUS_CONFIRMED = 1; |
27
|
|
|
|
28
|
|
|
/** @var int */ |
29
|
|
|
const STATUS_EMAIL_UNCONFIRMED = 2; |
30
|
|
|
|
31
|
|
|
/** @var bool */ |
32
|
|
|
public $timestamps = true; |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
protected $table = 'users'; |
36
|
|
|
|
37
|
|
|
/** @var array */ |
38
|
|
|
protected $fillable = [ |
39
|
|
|
'name', |
40
|
|
|
'email', |
41
|
|
|
'password', |
42
|
|
|
'picture', |
43
|
|
|
'status', |
44
|
|
|
'language_id', |
45
|
|
|
'role_id', |
46
|
|
|
'activation_code', |
47
|
|
|
'forgot_code', |
48
|
|
|
'forgot_time', |
49
|
|
|
'facebook_id', |
50
|
|
|
'twitter_id', |
51
|
|
|
'google_id' |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
/** @var array */ |
55
|
|
|
protected $hidden = [ |
56
|
|
|
'password', |
57
|
|
|
'activation_code', |
58
|
|
|
'forgot_code', |
59
|
|
|
'forgot_time', |
60
|
|
|
'facebook_id', |
61
|
|
|
'twitter_id', |
62
|
|
|
'google_id' |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
/** @var array */ |
66
|
|
|
protected $visible = [ |
67
|
|
|
'id', |
68
|
|
|
'name', |
69
|
|
|
'email', |
70
|
|
|
'picture', |
71
|
|
|
'status', |
72
|
|
|
'language_id', |
73
|
|
|
'role_id', |
74
|
|
|
'created_at', |
75
|
|
|
'updated_at', |
76
|
|
|
'language', |
77
|
|
|
'role', |
78
|
|
|
'userNotifications', |
79
|
|
|
'userTasks', |
80
|
|
|
'userAssignedTasks' |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
/** @var array */ |
84
|
|
|
protected $sortable = [ |
85
|
|
|
'id', |
86
|
|
|
'name', |
87
|
|
|
'email', |
88
|
|
|
'status', |
89
|
|
|
'created_at', |
90
|
|
|
'updated_at', |
91
|
|
|
]; |
92
|
|
|
|
93
|
|
|
/** @var array */ |
94
|
|
|
protected $searchable = [ |
95
|
|
|
'name', |
96
|
|
|
'email' |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
/** @var array */ |
100
|
|
|
protected $encrypted = [ |
101
|
|
|
'name', |
102
|
|
|
'email' |
103
|
|
|
]; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* User tokens. |
107
|
|
|
* |
108
|
|
|
* @return HasMany |
109
|
|
|
*/ |
110
|
|
|
public function userTokens() |
111
|
|
|
{ |
112
|
|
|
return $this->hasMany(UserToken::class, 'user_id', 'id'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* User notifications. |
117
|
|
|
* |
118
|
|
|
* @return HasMany |
119
|
|
|
*/ |
120
|
|
|
public function userNotifications() |
121
|
|
|
{ |
122
|
|
|
return $this->hasMany(UserNotification::class, 'user_id', 'id'); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Language. |
127
|
|
|
* |
128
|
|
|
* @return BelongsTo |
129
|
|
|
*/ |
130
|
|
|
public function language() |
131
|
|
|
{ |
132
|
|
|
return $this->belongsTo(Language::class, 'language_id', 'id'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Role. |
137
|
|
|
* |
138
|
|
|
* @return BelongsTo |
139
|
|
|
*/ |
140
|
|
|
public function role() |
141
|
|
|
{ |
142
|
|
|
return $this->belongsTo(Role::class, 'role_id', 'id'); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* User tasks. |
147
|
|
|
* |
148
|
|
|
* @return HasMany |
149
|
|
|
*/ |
150
|
|
|
public function userTasks() |
151
|
|
|
{ |
152
|
|
|
return $this->hasMany(UserTask::class, 'user_id', 'id'); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* User assigned tasks. |
157
|
|
|
* |
158
|
|
|
* @return HasMany |
159
|
|
|
*/ |
160
|
|
|
public function userAssignedTasks() |
161
|
|
|
{ |
162
|
|
|
return $this->hasMany(UserTask::class, 'assigned_user_id', 'id'); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|