1
|
|
|
<?php |
2
|
|
|
namespace Xetaravel\Models; |
3
|
|
|
|
4
|
|
|
use Eloquence\Behaviours\Sluggable; |
5
|
|
|
use Illuminate\Auth\Authenticatable; |
6
|
|
|
use Illuminate\Auth\Passwords\CanResetPassword; |
7
|
|
|
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
8
|
|
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
9
|
|
|
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; |
10
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
11
|
|
|
use Illuminate\Foundation\Auth\Access\Authorizable; |
12
|
|
|
use Illuminate\Notifications\Notifiable; |
13
|
|
|
use Spatie\MediaLibrary\HasMedia\HasMediaTrait; |
14
|
|
|
use Spatie\MediaLibrary\HasMedia\Interfaces\HasMediaConversions; |
15
|
|
|
use Ultraware\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract; |
16
|
|
|
use Ultraware\Roles\Traits\HasRoleAndPermission; |
17
|
|
|
use Xetaravel\Models\Entities\UserEntity; |
18
|
|
|
use Xetaravel\Models\Presenters\UserPresenter; |
19
|
|
|
|
20
|
|
|
class User extends Model implements |
21
|
|
|
AuthenticatableContract, |
22
|
|
|
AuthorizableContract, |
23
|
|
|
CanResetPasswordContract, |
24
|
|
|
HasRoleAndPermissionContract, |
25
|
|
|
HasMediaConversions |
26
|
|
|
{ |
27
|
|
|
use Authenticatable, |
28
|
|
|
Authorizable, |
29
|
|
|
CanResetPassword, |
30
|
|
|
Notifiable, |
31
|
|
|
SoftDeletes, |
32
|
|
|
Sluggable, |
33
|
|
|
HasRoleAndPermission, |
34
|
|
|
HasMediaTrait, |
35
|
|
|
UserEntity, |
36
|
|
|
UserPresenter; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The attributes that are mass assignable. |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
protected $fillable = [ |
44
|
|
|
'username', |
45
|
|
|
'email', |
46
|
|
|
'password', |
47
|
|
|
'slug', |
48
|
|
|
'register_ip', |
49
|
|
|
'last_login_ip', |
50
|
|
|
'last_login' |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* The attributes that should be hidden for arrays. |
55
|
|
|
* |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
protected $hidden = [ |
59
|
|
|
'password', |
60
|
|
|
'remember_token' |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* The accessors to append to the model's array form. |
65
|
|
|
* |
66
|
|
|
* @var array |
67
|
|
|
*/ |
68
|
|
|
protected $appends = [ |
69
|
|
|
'profile_background', |
70
|
|
|
|
71
|
|
|
// Media Model |
72
|
|
|
'avatar_small', |
73
|
|
|
'avatar_medium', |
74
|
|
|
'avatar_big', |
75
|
|
|
|
76
|
|
|
// Account Model |
77
|
|
|
'first_name', |
78
|
|
|
'last_name', |
79
|
|
|
'biography', |
80
|
|
|
'signature', |
81
|
|
|
'facebook', |
82
|
|
|
'twitter' |
83
|
|
|
]; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* The attributes that should be mutated to dates. |
87
|
|
|
* |
88
|
|
|
* @var array |
89
|
|
|
*/ |
90
|
|
|
protected $dates = [ |
91
|
|
|
'deleted_at' |
92
|
|
|
]; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Return the field to slug. |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function slugStrategy(): string |
100
|
|
|
{ |
101
|
|
|
return 'username'; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Register the related to the Model. |
106
|
|
|
* |
107
|
|
|
* @return void |
108
|
|
|
*/ |
109
|
|
|
public function registerMediaConversions() |
110
|
|
|
{ |
111
|
|
|
$this->addMediaConversion('thumbnail.small') |
112
|
|
|
->width(100) |
113
|
|
|
->height(100) |
114
|
|
|
->keepOriginalImageFormat(); |
115
|
|
|
|
116
|
|
|
$this->addMediaConversion('thumbnail.medium') |
117
|
|
|
->width(200) |
118
|
|
|
->height(200) |
119
|
|
|
->keepOriginalImageFormat(); |
120
|
|
|
|
121
|
|
|
$this->addMediaConversion('thumbnail.big') |
122
|
|
|
->width(300) |
123
|
|
|
->height(300) |
124
|
|
|
->keepOriginalImageFormat(); |
125
|
|
|
|
126
|
|
|
$this->addMediaConversion('original') |
127
|
|
|
->keepOriginalImageFormat(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Get the comments for the user. |
132
|
|
|
* |
133
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
134
|
|
|
*/ |
135
|
|
|
public function comments() |
136
|
|
|
{ |
137
|
|
|
return $this->hasMany(Comment::class); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Get the articles for the user. |
142
|
|
|
* |
143
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
144
|
|
|
*/ |
145
|
|
|
public function articles() |
146
|
|
|
{ |
147
|
|
|
return $this->hasMany(Article::class); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Get the account for the user. |
152
|
|
|
* |
153
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne |
154
|
|
|
*/ |
155
|
|
|
public function account() |
156
|
|
|
{ |
157
|
|
|
return $this->hasOne(Account::class); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Get the roles for the user. |
162
|
|
|
* |
163
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
164
|
|
|
*/ |
165
|
|
|
public function roles() |
166
|
|
|
{ |
167
|
|
|
return $this->belongsToMany(\Ultraware\Roles\Models\Role::class); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Get the badges for the user. |
172
|
|
|
* |
173
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
174
|
|
|
*/ |
175
|
|
|
public function badges() |
176
|
|
|
{ |
177
|
|
|
return $this->belongsToMany(Badge::class)->withTimestamps(); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|