I am having a body like this
{ "userid": 435, "territories_id":[176,139] }
Where userid is the drupal user id. And I need to update field field_user_territory which is a taxonomy field. I do not want earlier territories to go instead I need to update with 2 more territories.
This is the code I tried.
foreach ($territories_id as $territory_id) { $user = DrupaluserEntityUser::load($userid); $user->field_user_territory->target_id = $territory_id; $user->save(); }
But here the earlier territories got vanished.