File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
laravel/app/Http/Controllers/Api Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -133,16 +133,18 @@ public function update(Update $request, $id)
133
133
\Cache::forget ('user_r_p_ ' .$ user ->id );
134
134
}
135
135
136
-
137
- $ p_all = Permission::all ();//获取所有权限
138
-
139
- foreach ($ p_all as $ p ) {
140
- $ role ->revokePermissionTo ($ p ); // 移除与角色关联的所有权限
136
+ // $p_all = Permission::all();//获取所有权限
137
+ // foreach ($p_all as $p) {
138
+ // $role->revokePermissionTo($p); // 将会移除与角色关联的所有权限
139
+ // }
140
+ // Fix: 一并移除了权限的错误
141
+ foreach ($ role ->permissions as $ permission ) {
142
+ $ role ->permissions ()->detach ($ permission ->id ); // 仅移除 permission_role 表与角色关联的权限
141
143
}
142
144
143
145
foreach ($ permissions as $ permission ) {
144
- $ p = Permission::where ('id ' , '= ' , $ permission )->firstOrFail (); //从数据库中获取相应权限
145
- $ role ->givePermissionTo ($ p ); // 分配权限到角色
146
+ $ p = Permission::where ('id ' , '= ' , $ permission )->first (); //从数据库中获取相应权限
147
+ $ p && $ role ->givePermissionTo ($ p ); // 分配权限到角色
146
148
}
147
149
148
150
return $ this ->out (200 , ['data ' => ['id ' => $ id ]]);
You can’t perform that action at this time.
0 commit comments