1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Fort\Models; |
6
|
|
|
|
7
|
|
|
use Rinvex\Tenants\Traits\Tenantable; |
8
|
|
|
use Cortex\Foundation\Traits\Auditable; |
9
|
|
|
use Rinvex\Cacheable\CacheableEloquent; |
10
|
|
|
use Rinvex\Fort\Models\User as BaseUser; |
11
|
|
|
use Rinvex\Attributes\Traits\Attributable; |
12
|
|
|
use Spatie\MediaLibrary\HasMedia\HasMedia; |
13
|
|
|
use Spatie\Activitylog\Traits\HasActivity; |
14
|
|
|
use Spatie\MediaLibrary\HasMedia\HasMediaTrait; |
15
|
|
|
use Cortex\Fort\Notifications\PasswordResetNotification; |
16
|
|
|
use Cortex\Fort\Notifications\EmailVerificationNotification; |
17
|
|
|
use Cortex\Fort\Notifications\PhoneVerificationNotification; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Cortex\Fort\Models\User. |
21
|
|
|
* |
22
|
|
|
* @property int $id |
|
|
|
|
23
|
|
|
* @property string $username |
|
|
|
|
24
|
|
|
* @property string $password |
|
|
|
|
25
|
|
|
* @property string|null $remember_token |
|
|
|
|
26
|
|
|
* @property string $email |
|
|
|
|
27
|
|
|
* @property bool $email_verified |
|
|
|
|
28
|
|
|
* @property \Carbon\Carbon $email_verified_at |
|
|
|
|
29
|
|
|
* @property string $phone |
|
|
|
|
30
|
|
|
* @property bool $phone_verified |
|
|
|
|
31
|
|
|
* @property \Carbon\Carbon $phone_verified_at |
|
|
|
|
32
|
|
|
* @property string $name_prefix |
|
|
|
|
33
|
|
|
* @property string $first_name |
|
|
|
|
34
|
|
|
* @property string $middle_name |
|
|
|
|
35
|
|
|
* @property string $last_name |
|
|
|
|
36
|
|
|
* @property string $name_suffix |
|
|
|
|
37
|
|
|
* @property string $title |
|
|
|
|
38
|
|
|
* @property string $country_code |
|
|
|
|
39
|
|
|
* @property string $language_code |
|
|
|
|
40
|
|
|
* @property array $two_factor |
|
|
|
|
41
|
|
|
* @property string $birthday |
|
|
|
|
42
|
|
|
* @property string $gender |
|
|
|
|
43
|
|
|
* @property bool $is_active |
|
|
|
|
44
|
|
|
* @property \Carbon\Carbon $last_activity |
|
|
|
|
45
|
|
|
* @property \Carbon\Carbon|null $created_at |
|
|
|
|
46
|
|
|
* @property \Carbon\Carbon|null $updated_at |
|
|
|
|
47
|
|
|
* @property \Carbon\Carbon|null $deleted_at |
|
|
|
|
48
|
|
|
* @property \Illuminate\Database\Eloquent\Collection|\Cortex\Fort\Models\Ability[] $abilities |
|
|
|
|
49
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Cortex\Foundation\Models\Log[] $activity |
|
|
|
|
50
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Cortex\Foundation\Models\Log[] $actions |
|
|
|
|
51
|
|
|
* @property-read \Illuminate\Support\Collection $all_abilities |
|
|
|
|
52
|
|
|
* @property-read \Rinvex\Country\Country $country |
|
|
|
|
53
|
|
|
* @property mixed $entity |
|
|
|
|
54
|
|
|
* @property-read \Rinvex\Language\Language $language |
|
|
|
|
55
|
|
|
* @property-read string $name |
|
|
|
|
56
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications |
|
|
|
|
57
|
|
|
* @property \Illuminate\Database\Eloquent\Collection|\Cortex\Fort\Models\Role[] $roles |
|
|
|
|
58
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Rinvex\Fort\Models\Session[] $sessions |
|
|
|
|
59
|
|
|
* @property \Illuminate\Database\Eloquent\Collection|\Cortex\Tenants\Models\Tenant[] $tenants |
|
|
|
|
60
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Rinvex\Fort\Models\Socialite[] $socialites |
|
|
|
|
61
|
|
|
* |
62
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User hasAttribute($key, $value) |
63
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User role($roles) |
64
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereBirthday($value) |
65
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereCountryCode($value) |
66
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereCreatedAt($value) |
67
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereDeletedAt($value) |
68
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereEmail($value) |
69
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereEmailVerified($value) |
70
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereEmailVerifiedAt($value) |
71
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereFirstName($value) |
72
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereGender($value) |
73
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereId($value) |
74
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereIsActive($value) |
75
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereLanguageCode($value) |
76
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereLastActivity($value) |
77
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereLastName($value) |
78
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereMiddleName($value) |
79
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereNamePrefix($value) |
80
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereNameSuffix($value) |
81
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User wherePassword($value) |
82
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User wherePhone($value) |
83
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User wherePhoneVerified($value) |
84
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User wherePhoneVerifiedAt($value) |
85
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereRememberToken($value) |
86
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereTitle($value) |
87
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereTwoFactor($value) |
88
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereUpdatedAt($value) |
89
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User whereUsername($value) |
90
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User withAllTenants($tenants, $group = null) |
91
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User withAnyTenants($tenants, $group = null) |
92
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User withTenants($tenants, $group = null) |
93
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User withoutAnyTenants() |
94
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\User withoutTenants($tenants, $group = null) |
95
|
|
|
* @mixin \Eloquent |
96
|
|
|
*/ |
97
|
|
|
class User extends BaseUser implements HasMedia |
98
|
|
|
{ |
99
|
|
|
// @TODO: Strangely, this issue happens only here!!! |
|
|
|
|
100
|
|
|
// Duplicate trait usage to fire attached events for cache |
101
|
|
|
// flush before other events in other traits specially LogsActivity, |
102
|
|
|
// otherwise old cached queries used and no changelog recorded on update. |
103
|
|
|
use CacheableEloquent; |
104
|
|
|
use Auditable; |
105
|
|
|
use Tenantable; |
106
|
|
|
use HasActivity; |
107
|
|
|
use Attributable; |
108
|
|
|
use HasMediaTrait; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Indicates whether to log only dirty attributes or all. |
112
|
|
|
* |
113
|
|
|
* @var bool |
114
|
|
|
*/ |
115
|
|
|
protected static $logOnlyDirty = true; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* The attributes that are logged on change. |
119
|
|
|
* |
120
|
|
|
* @var array |
121
|
|
|
*/ |
122
|
|
|
protected static $logAttributes = [ |
123
|
|
|
'username', |
124
|
|
|
'email', |
125
|
|
|
'email_verified', |
126
|
|
|
'phone', |
127
|
|
|
'phone_verified', |
128
|
|
|
'name_prefix', |
129
|
|
|
'first_name', |
130
|
|
|
'middle_name', |
131
|
|
|
'last_name', |
132
|
|
|
'name_suffix', |
133
|
|
|
'title', |
134
|
|
|
'country_code', |
135
|
|
|
'language_code', |
136
|
|
|
'birthday', |
137
|
|
|
'gender', |
138
|
|
|
'is_active', |
139
|
|
|
'abilities', |
140
|
|
|
'roles', |
141
|
|
|
]; |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* The attributes that are ignored on change. |
145
|
|
|
* |
146
|
|
|
* @var array |
147
|
|
|
*/ |
148
|
|
|
protected static $ignoreChangedAttributes = [ |
149
|
|
|
'password', |
150
|
|
|
'two_factor', |
151
|
|
|
'email_verified_at', |
152
|
|
|
'phone_verified_at', |
153
|
|
|
'last_activity', |
154
|
|
|
'created_at', |
155
|
|
|
'updated_at', |
156
|
|
|
'deleted_at', |
157
|
|
|
]; |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* {@inheritdoc} |
161
|
|
|
*/ |
162
|
|
|
protected $passwordResetNotificationClass = PasswordResetNotification::class; |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* {@inheritdoc} |
166
|
|
|
*/ |
167
|
|
|
protected $emailVerificationNotificationClass = EmailVerificationNotification::class; |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* {@inheritdoc} |
171
|
|
|
*/ |
172
|
|
|
protected $phoneVerificationNotificationClass = PhoneVerificationNotification::class; |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Get the route key for the model. |
176
|
|
|
* |
177
|
|
|
* @return string |
178
|
|
|
*/ |
179
|
|
|
public function getRouteKeyName(): string |
180
|
|
|
{ |
181
|
|
|
return 'username'; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Register media collections. |
186
|
|
|
* |
187
|
|
|
* @return void |
188
|
|
|
*/ |
189
|
|
|
public function registerMediaCollections(): void |
190
|
|
|
{ |
191
|
|
|
$this->addMediaCollection('profile_picture')->singleFile(); |
192
|
|
|
$this->addMediaCollection('cover_photo')->singleFile(); |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.