How can I get the taxonomy term name from a term ID? I'm trying to get a taxonomy term name by term ID. According to another post, I should load the term first:

$term = \Drupal::entityTypeManager()-&gt;getStorage('taxonomy')-&gt;load($tid);


But then I get this error :


  Notice: Undefined property: Drupal\Core\Entity\Plugin\DataType\EntityReference::$target


What am I doing wrong? How can I get the term name?
Or you can simply use The entity Term class:

use Drupal\taxonomy\Entity\Term;


and in your code:

$term = Term::load($tid);
$name = $term-&gt;getName();