I have tried the following code, but something doesn't work, could you please help. I need to deactivate several accounts at once, if they satisfy the conditions:
$ids = \Drupal::entityQuery('user')
->condition('roles', 'student')
->condition('field_school_id', $node_id)
->execute();
$users = User::loadMultiple($ids);
$storage_handler = \Drupal::entityTypeManager()->getStorage("user");
foreach($users as $user){
$entity = $storage_handler->load($user->id());
$entity->set("status", 0);
$storage_handler->save($entity); // THE PROBLEM IS IN THIS LINE
}