fix givePermission relationship

This commit is contained in:
2023-03-13 11:25:25 +10:00
parent 8a3d9eec03
commit 970618f561

View File

@@ -119,9 +119,15 @@ class User extends Authenticatable implements Auditable
return ['permission' => $permission];
});
return $this->permissions()->firstOrCreateMany($permissions->toArray());
$existingPermissions = $this->permissions()->whereIn('permission', $permissions->pluck('permission'))->get();
$newPermissions = $permissions->reject(function ($permission) use ($existingPermissions) {
return $existingPermissions->contains('permission', $permission['permission']);
});
return $this->permissions()->createMany($newPermissions->toArray());
}
/**
* Revoke permissions from the user
*