1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Auth\Passwords\CanResetPassword; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use Illuminate\Foundation\Auth\Access\Authorizable; |
8
|
|
|
use Illuminate\Notifications\Notifiable; |
9
|
|
|
use Tymon\JWTAuth\Contracts\JWTSubject as AuthenticatableUserContract; |
10
|
|
|
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; |
11
|
|
|
use Illuminate\Contracts\Auth\Authenticatable; |
12
|
|
|
use Illuminate\Auth\Authenticatable as AuthenticatableTrait; |
13
|
|
|
use Zizaco\Entrust\Traits\EntrustUserTrait; |
14
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany; |
15
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany; |
16
|
|
|
|
17
|
|
|
class User extends Model implements AuthenticatableUserContract, Authenticatable, CanResetPasswordContract |
18
|
|
|
{ |
19
|
|
|
use AuthenticatableTrait, Authorizable, CanResetPassword, Notifiable, EntrustUserTrait { |
20
|
|
|
EntrustUserTrait::can insteadof Authorizable; |
21
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The attributes that are mass assignable. |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $fillable = [ |
30
|
|
|
'name', 'email', 'password', 'activated' |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The attributes that should be hidden for arrays. |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $hidden = [ |
39
|
|
|
'password', 'remember_token', |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return mixed |
44
|
|
|
*/ |
45
|
|
|
public function getJWTIdentifier() |
46
|
|
|
{ |
47
|
|
|
return $this->getKey(); // Eloquent model method |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
|
|
public function getJWTCustomClaims() |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
'user' => [ |
57
|
|
|
'id' => $this->id, |
58
|
|
|
], |
59
|
|
|
]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return BelongsToMany |
64
|
|
|
*/ |
65
|
|
|
public function roles() |
66
|
|
|
{ |
67
|
|
|
return $this->belongsToMany(Role::class); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get the activation record associated with the user. |
72
|
|
|
*/ |
73
|
|
|
public function activation() |
74
|
|
|
{ |
75
|
|
|
return $this->hasOne(Activation::class); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|