hi im updating the admin user direct permissions by this way but i get GuardDoesNotMatch
error, i have seprate admins and users table and i set admin guard when admin log in.
public function update(Request $request){
// dd($request);
$this->validate($request, [
'user_id' => 'required',
'permission_id' => 'required'
]);
$user_id = $request->get('user_id');
$user = User::findOrFail($user_id);
$permissions = $request->get('permission_id');
if(!is_array($permissions)){
$permissions = (array)$permissions;
}
$permissionArr = [];
// Check if no permission selected.
if(!empty($permissions)){
foreach ($permissions as $permission) {
$permissionArr[] = Permission::find($permission);
}
}
$user->syncPermissions($permissionArr);
return "success";
}
ERROR:
message The given role or permission should use guard
user, web, api
instead ofadmin
. exception Spatie\Permission\Exceptions\GuardDoesNotMatch
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire