1
|
|
|
<?php namespace Distilleries\Expendable\Models; |
2
|
|
|
|
3
|
|
|
use Distilleries\Expendable\Contracts\LockableContract; |
4
|
|
|
use Distilleries\Expendable\Helpers\UserUtils; |
5
|
|
|
use Distilleries\Expendable\Mails\ResetPasswordNotification; |
6
|
|
|
use Distilleries\PermissionUtil\Contracts\PermissionUtilContract; |
7
|
|
|
use Illuminate\Auth\Authenticatable; |
8
|
|
|
use Illuminate\Auth\Passwords\CanResetPassword; |
9
|
|
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
10
|
|
|
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; |
11
|
|
|
use Illuminate\Foundation\Auth\Access\Authorizable; |
12
|
|
|
use Illuminate\Notifications\Notifiable; |
13
|
|
|
|
14
|
|
|
class User extends BaseModel implements AuthenticatableContract, CanResetPasswordContract, PermissionUtilContract, LockableContract { |
15
|
|
|
|
16
|
|
|
use Authenticatable, Authorizable, CanResetPassword, \Distilleries\Expendable\Models\StatusTrait, LockableTrait; |
17
|
|
|
use Notifiable; |
18
|
|
|
protected $tabPermission = []; |
19
|
|
|
protected $fillable = [ |
20
|
|
|
'email', |
21
|
|
|
'password', |
22
|
|
|
'status', |
23
|
|
|
'role_id' |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The attributes excluded from the model's JSON form. |
28
|
|
|
* |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
296 |
|
protected $hidden = ['password', 'remember_token']; |
32
|
|
|
|
33
|
296 |
|
public function role() |
34
|
|
|
{ |
35
|
|
|
return $this->belongsTo('Distilleries\Expendable\Models\Role'); |
36
|
396 |
|
} |
37
|
|
|
|
38
|
396 |
|
public static function boot() |
39
|
396 |
|
{ |
40
|
297 |
|
parent::boot(); |
41
|
|
|
self::observe(new \Distilleries\Expendable\Observers\PasswordObserver); |
42
|
|
|
} |
43
|
|
|
|
44
|
276 |
|
|
45
|
|
|
|
46
|
|
|
public function hasAccess($key) |
47
|
276 |
|
{ |
48
|
207 |
|
|
49
|
272 |
|
if (!empty($this->role->overide_permission)) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
return true; |
52
|
4 |
|
} |
53
|
|
|
|
54
|
|
|
return UserUtils::hasAccess($key); |
55
|
20 |
|
} |
56
|
|
|
|
57
|
20 |
|
public function getFirstRedirect($left) |
58
|
|
|
{ |
59
|
|
|
foreach ($left as $item) |
60
|
20 |
|
{ |
61
|
15 |
|
|
62
|
16 |
|
if (!empty($item['action']) && $this->hasAccess($item['action'])) |
63
|
|
|
{ |
64
|
8 |
|
return preg_replace('/\/index/i', '', action($item['action'])); |
65
|
6 |
|
|
66
|
8 |
|
} else if (!empty($item['submenu'])) |
67
|
|
|
{ |
68
|
8 |
|
$redirect = $this->getFirstRedirect($item['submenu']); |
69
|
6 |
|
|
70
|
5 |
|
if (!empty($redirect)) |
71
|
|
|
{ |
72
|
|
|
return $redirect; |
73
|
3 |
|
} |
74
|
|
|
|
75
|
3 |
|
} |
76
|
|
|
|
77
|
4 |
|
} |
78
|
|
|
|
79
|
|
|
return ''; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Send the password reset notification. |
85
|
|
|
* |
86
|
|
|
* @param string $token |
87
|
|
|
* @return void |
88
|
|
|
*/ |
89
|
|
|
public function sendPasswordResetNotification($token) |
90
|
|
|
{ |
91
|
|
|
$this->notify(new ResetPasswordNotification($token)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.