1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use App\Infrastructure\Auth\Notifications\ResetPasswordQueued; |
6
|
|
|
use App\Infrastructure\Auth\Notifications\VerifyEmailQueued; |
7
|
|
|
use App\Infrastructure\Contracts\Auth\HasRole; |
8
|
|
|
use App\Infrastructure\Contracts\Auth\MustVerifyEmail; |
9
|
|
|
use App\Infrastructure\Foundation\Auth\User as Authenticatable; |
10
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
11
|
|
|
use Illuminate\Notifications\Notifiable; |
12
|
|
|
use Laravel\Sanctum\HasApiTokens; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @method static \Database\Factories\UserFactory<static> factory(callable|array|int|null $count = null, callable|array $state = []) Get a new factory instance for the model. |
16
|
|
|
*/ |
17
|
|
|
class User extends Authenticatable implements HasRole, MustVerifyEmail |
18
|
|
|
{ |
19
|
|
|
use HasApiTokens, HasFactory, Notifiable, |
|
|
|
|
20
|
|
|
Concerns\User\Attribute, |
21
|
|
|
Concerns\User\Event, |
22
|
|
|
Concerns\User\Relation; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritDoc} |
26
|
|
|
* |
27
|
|
|
* @var array<int, string> |
28
|
|
|
*/ |
29
|
|
|
protected $fillable = [ |
30
|
|
|
'username', |
31
|
|
|
'name', |
32
|
|
|
'email', |
33
|
|
|
'password', |
34
|
|
|
'bio', |
35
|
|
|
'is_subscribe_to_newsletter', |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritDoc} |
40
|
|
|
* |
41
|
|
|
* @var array<int, string> |
42
|
|
|
*/ |
43
|
|
|
protected $hidden = [ |
44
|
|
|
'password', |
45
|
|
|
'remember_token', |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritDoc} |
50
|
|
|
* |
51
|
|
|
* @var array<string, string> |
52
|
|
|
*/ |
53
|
|
|
protected $casts = [ |
54
|
|
|
'email_verified_at' => 'datetime', |
55
|
|
|
'is_subscribe_to_newsletter' => 'boolean', |
56
|
|
|
]; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritDoc} |
60
|
|
|
*/ |
61
|
1 |
|
public function sendEmailVerificationNotification() |
62
|
|
|
{ |
63
|
1 |
|
$this->notify(new VerifyEmailQueued); |
64
|
1 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritDoc} |
68
|
|
|
*/ |
69
|
3 |
|
public function sendPasswordResetNotification($token) |
70
|
|
|
{ |
71
|
3 |
|
$this->notify(new ResetPasswordQueued($token)); |
72
|
3 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritDoc} |
76
|
|
|
*/ |
77
|
|
|
public function isAdmin(): bool |
78
|
|
|
{ |
79
|
|
|
return $this->hasRole(Role::ROLE_ADMIN); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritDoc} |
84
|
|
|
*/ |
85
|
|
|
public function isManager(): bool |
86
|
|
|
{ |
87
|
|
|
return $this->hasRole(Role::ROLE_MANAGER); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritDoc} |
92
|
|
|
*/ |
93
|
|
|
public function isStaff(): bool |
94
|
|
|
{ |
95
|
|
|
return $this->hasRole(Role::ROLE_STAFF); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|