Drupal 9 Get taxonomy term objects by vocabulary machine name vid

To get taxonomy term objects by vocabulary machine name (vid) in Drupal 9, you can use the following code snippet:

$terms = \Drupal::entityTypeManager()
  ->getStorage('taxonomy_term')
  ->loadTree($vocabulary_machine_name);

foreach ($terms as $term) {
  // Do something with each term object.
}

In the code above, replace $vocabulary_machine_name with the machine name of the vocabulary you want to retrieve terms from. This code uses the loadTree() method to load the taxonomy terms for the specified vocabulary. It returns an array of term objects, which you can then iterate over and perform any desired operations.

Please note that this code assumes you are working within a Drupal 9 context and have the necessary Drupal core and taxonomy modules installed and enabled.