1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App; |
4
|
|
|
|
5
|
|
|
//use Illuminate\Foundation\Auth\User as Authenticatable; |
|
|
|
|
6
|
|
|
use App\Libraries\Presenterable\Presenterable; |
7
|
|
|
use App\Libraries\Presenterable\Presenters\UserPresenter; |
8
|
|
|
use App\Repositories\RolesRepository; |
9
|
|
|
use App\Traits\ActivateableTrait; |
10
|
|
|
use App\Traits\Confirmed; |
11
|
|
|
use Keyhunter\Administrator\AuthRepository as Authenticatable; |
12
|
|
|
use App\Traits\HasImages; |
13
|
|
|
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; |
14
|
|
|
use Illuminate\Auth\Passwords\CanResetPassword; |
15
|
|
|
|
16
|
|
|
class User extends Authenticatable implements CanResetPasswordContract |
17
|
|
|
{ |
18
|
|
|
use Presenterable, Confirmed, ActivateableTrait, HasImages, CanResetPassword; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The attributes that are mass assignable. |
22
|
|
|
* |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
protected $fillable = [ |
26
|
|
|
'name', 'email', 'password', 'role_id', 'confirmation_code', 'confirmed' |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The attributes that should be hidden for arrays. |
31
|
|
|
* |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
protected $hidden = [ |
35
|
|
|
'password', 'remember_token', |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var UserPresenter |
40
|
|
|
*/ |
41
|
|
|
protected $presenter = UserPresenter::class; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
45
|
|
|
*/ |
46
|
|
|
public function vendors() |
47
|
|
|
{ |
48
|
|
|
return $this->hasMany(Vendor::class); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne |
53
|
|
|
*/ |
54
|
|
|
public function wallet() |
55
|
|
|
{ |
56
|
|
|
return $this->hasOne(Wallet::class); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne |
61
|
|
|
*/ |
62
|
|
|
public function profile() |
63
|
|
|
{ |
64
|
|
|
return $this->hasOne(Profile::class, 'user_id', 'id'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
69
|
|
|
*/ |
70
|
|
|
public function involved() |
71
|
|
|
{ |
72
|
|
|
return $this->hasMany(Involved::class, 'user_id', 'id'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
78
|
|
|
*/ |
79
|
|
|
public function socialite() |
80
|
|
|
{ |
81
|
|
|
return $this->belongsTo(Socialite::class, 'id', 'user_id'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Check if current user is socialite user. |
86
|
|
|
* |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
|
public function isSocialite() |
90
|
|
|
{ |
91
|
|
|
return (bool)$this->socialite; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Check if user have avatar. |
96
|
|
|
* |
97
|
|
|
* @return bool |
98
|
|
|
*/ |
99
|
|
|
public function checkAvatar() |
100
|
|
|
{ |
101
|
|
|
return (bool)$this->images()->avatar()->first(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function isAdmin() |
105
|
|
|
{ |
106
|
|
|
$admin = (new RolesRepository)->getAdminRole(); |
107
|
|
|
|
108
|
|
|
return $this->role_id == $admin->id; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Check if user has wallet. |
113
|
|
|
* |
114
|
|
|
* @return bool |
115
|
|
|
*/ |
116
|
|
|
public function haveWallet() |
117
|
|
|
{ |
118
|
|
|
//return (bool) $this->wallet()->first(); |
|
|
|
|
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.