1 | <?php |
||||||
2 | |||||||
3 | namespace Yeelight\Models; |
||||||
4 | |||||||
5 | use Illuminate\Auth\Authenticatable; |
||||||
6 | use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
||||||
7 | use Prettus\Repository\Traits\TransformableTrait; |
||||||
8 | use Yeelight\Services\Image\Models\Traits\YeelightHasOneImageTrait; |
||||||
9 | use Yeelight\Services\Image\Models\Traits\YeelightUploadOneImageTrait; |
||||||
10 | use Yeelight\Traits\HasPermissions; |
||||||
11 | |||||||
12 | /** |
||||||
13 | * Class AdminUser |
||||||
14 | * |
||||||
15 | * @category Yeelight |
||||||
16 | * |
||||||
17 | * @package Yeelight\Models |
||||||
18 | * |
||||||
19 | * @author Sheldon Lee <[email protected]> |
||||||
20 | * |
||||||
21 | * @license https://opensource.org/licenses/MIT MIT |
||||||
22 | * |
||||||
23 | * @link https://www.yeelight.com |
||||||
24 | */ |
||||||
25 | class AdminUser extends BaseModel implements AuthenticatableContract |
||||||
26 | { |
||||||
27 | use TransformableTrait, |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
28 | Authenticatable, |
||||||
29 | HasPermissions, |
||||||
30 | YeelightHasOneImageTrait, |
||||||
31 | YeelightUploadOneImageTrait; |
||||||
32 | |||||||
33 | /** |
||||||
34 | * Indicates if the model should be auto set user_id. |
||||||
35 | * |
||||||
36 | * @var bool |
||||||
37 | */ |
||||||
38 | protected $autoUserId = false; |
||||||
39 | |||||||
40 | /** |
||||||
41 | * Indicates if the model should be recorded ips. |
||||||
42 | * |
||||||
43 | * @var bool |
||||||
44 | */ |
||||||
45 | protected $ips = false; |
||||||
46 | |||||||
47 | /** |
||||||
48 | * Indicates if the model should be recorded users. |
||||||
49 | * |
||||||
50 | * @var bool |
||||||
51 | */ |
||||||
52 | protected $update_users = false; |
||||||
53 | |||||||
54 | protected $primaryKey = 'id'; |
||||||
55 | |||||||
56 | protected $fillable = ['username', 'password', 'name', 'yeelight_image_id']; |
||||||
57 | |||||||
58 | // Fields to be converted to Carbon object automatically |
||||||
59 | protected $dates = []; |
||||||
60 | |||||||
61 | /** |
||||||
62 | * The attributes that should be hidden for arrays. |
||||||
63 | * |
||||||
64 | * @var array |
||||||
65 | */ |
||||||
66 | protected $hidden = [ |
||||||
67 | 'remember_token', |
||||||
68 | ]; |
||||||
69 | |||||||
70 | /** |
||||||
71 | * Create a new Eloquent model instance. |
||||||
72 | * |
||||||
73 | * @param array $attributes attributes |
||||||
74 | */ |
||||||
75 | public function __construct(array $attributes = []) |
||||||
76 | { |
||||||
77 | $this->setTable(config('yeelight.backend.database.admin_users_table')); |
||||||
78 | |||||||
79 | parent::__construct($attributes); |
||||||
80 | } |
||||||
81 | |||||||
82 | public function onCreating() |
||||||
83 | { |
||||||
84 | parent::onCreating(); |
||||||
85 | |||||||
86 | //密码 |
||||||
87 | $this->password = bcrypt($this->password); |
||||||
0 ignored issues
–
show
|
|||||||
88 | |||||||
89 | //头像 |
||||||
90 | $yeelightImage = $this->uploadOne('avatar'); |
||||||
91 | $this->yeelight_image_id = $yeelightImage ? $yeelightImage->getYeelightImageId() : null; |
||||||
0 ignored issues
–
show
|
|||||||
92 | } |
||||||
93 | |||||||
94 | public function onCreated() |
||||||
95 | { |
||||||
96 | parent::onCreated(); |
||||||
97 | |||||||
98 | //头像 |
||||||
99 | if ($this->yeelight_image_id) { |
||||||
100 | $this->yeelight_image->user_id = $this->attributes[$this->getKeyName()]; |
||||||
0 ignored issues
–
show
The property
yeelight_image does not exist on Yeelight\Models\AdminUser . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
101 | $this->yeelight_image->save(); |
||||||
0 ignored issues
–
show
The method
save() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
102 | } |
||||||
103 | |||||||
104 | //权限 |
||||||
105 | $permissions = array_filter(request()->get('permissions', [])); |
||||||
106 | if (!empty($permissions)) { |
||||||
107 | $this->permissions()->sync($permissions); |
||||||
108 | } |
||||||
109 | |||||||
110 | //角色 |
||||||
111 | $roles = array_filter(request()->get('roles', [])); |
||||||
112 | if (!empty($roles)) { |
||||||
113 | $this->roles()->sync($roles); |
||||||
114 | } |
||||||
115 | } |
||||||
116 | |||||||
117 | public function onUpdating() |
||||||
118 | { |
||||||
119 | parent::onUpdating(); |
||||||
120 | |||||||
121 | //密码 |
||||||
122 | if (request()->get('password') |
||||||
123 | && $this->password != request()->get('password') |
||||||
124 | ) { |
||||||
125 | $this->password = bcrypt(request()->get('password')); |
||||||
0 ignored issues
–
show
|
|||||||
126 | } |
||||||
127 | |||||||
128 | //头像 |
||||||
129 | $yeelightImage = $this->uploadOne('avatar'); |
||||||
130 | if ($yeelightImage) { |
||||||
0 ignored issues
–
show
|
|||||||
131 | $this->yeelight_image_id = $yeelightImage->getYeelightImageId(); |
||||||
0 ignored issues
–
show
|
|||||||
132 | $this->yeelight_image->user_id = $this->attributes[$this->getKeyName()]; |
||||||
0 ignored issues
–
show
The property
yeelight_image does not exist on Yeelight\Models\AdminUser . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||
133 | $this->yeelight_image->save(); |
||||||
134 | } |
||||||
135 | |||||||
136 | //权限 |
||||||
137 | $permissions = array_filter(request()->get('permissions', [])); |
||||||
138 | if (!empty($permissions)) { |
||||||
139 | $this->permissions()->sync($permissions); |
||||||
140 | } |
||||||
141 | |||||||
142 | //角色 |
||||||
143 | $roles = array_filter(request()->get('roles', [])); |
||||||
144 | if (!empty($roles)) { |
||||||
145 | $this->roles()->sync($roles); |
||||||
146 | } |
||||||
147 | } |
||||||
148 | |||||||
149 | public function onDeleting() |
||||||
150 | { |
||||||
151 | parent::onDeleting(); |
||||||
152 | |||||||
153 | //权限 |
||||||
154 | $this->permissions()->sync([]); |
||||||
155 | |||||||
156 | //角色 |
||||||
157 | $this->roles()->sync([]); |
||||||
158 | } |
||||||
159 | } |
||||||
160 |