1 | <?php |
||
2 | |||
3 | namespace App; |
||
4 | |||
5 | use App\Traits\GravatarTrait; |
||
6 | use Illuminate\Foundation\Auth\User as Authenticatable; |
||
7 | use Illuminate\Notifications\Notifiable; |
||
8 | |||
9 | class User extends Authenticatable |
||
10 | { |
||
11 | use Notifiable; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
12 | use GravatarTrait; |
||
0 ignored issues
–
show
|
|||
13 | |||
14 | protected $table = 'users'; |
||
15 | |||
16 | /** |
||
17 | * The attributes that are mass assignable. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $fillable = [ |
||
22 | 'name', |
||
23 | 'login', |
||
24 | 'role_id', |
||
25 | 'email', |
||
26 | 'password', |
||
27 | 'active', |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * The attributes that should be hidden for arrays. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $hidden = [ |
||
36 | 'active', |
||
37 | 'role_id', |
||
38 | 'password', |
||
39 | 'remember_token', |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * The attributes that should be cast to native types. |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $casts = [ |
||
48 | 'email_verified_at' => 'datetime', |
||
49 | ]; |
||
50 | |||
51 | public function isAdmin() |
||
52 | { |
||
53 | return $this->role_id == 3; |
||
54 | } |
||
55 | |||
56 | public function isModerator() |
||
57 | { |
||
58 | return $this->role_id == 2; |
||
59 | } |
||
60 | |||
61 | public function roles() |
||
62 | { |
||
63 | return $this->belongsTo(Role::class, 'role_id', 'id'); |
||
64 | } |
||
65 | |||
66 | //admin password |
||
67 | public function setNewPasswordAttribute($value) |
||
68 | { |
||
69 | if ($value) { |
||
70 | $this->attributes['password'] = bcrypt($value); |
||
71 | } |
||
72 | } |
||
73 | } |
||
74 |