It's easy way to tackle this problem, Sometimes we face this issue and take the query help and get the parent id, but we have here solution for this issue.
Just write the loadParent syntax as per given instructions:
Syntax:
Just write the loadParent syntax as per given instructions:
Syntax:
$term_id = $node->get('field_category')->target_id;
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($term_id);
$parentids = $term->parent->target_id;
OR
$parent = reset($parent); //reset the parent array
$parentids = $parent->id(); //get the parent id
Note: If have any suggestions or issue regarding 'How to get the Parent id from term id in drupal 8?' then you can ask by comments.