How can I get the taxonomy tree by the vocabulary ID? I want load all the taxonomy terms by their vocabulary ID in Drupal 8. In Drupal 7, I would use the following code. 

$terms = taxonomy_get_tree($vid);


What code should I use in Drupal 8?
You can load terms using the entity query,

$terms =\Drupal::entityTypeManager()-&gt;getStorage('taxonomy_term')-&gt;loadTree($vid);
foreach ($terms as $term) {
     $term_data[] = array(
      "id" =&gt; $term-&gt;tid,
      "name" =&gt; $term-&gt;name
     );
    }