title: Laravel get data from many to many relation
body: <p>For a school project, I'm creating a website in the Laravel framework.
  I can't work with the data from a many-to-many table in my controller.</p>
  
  <p>Here are my models:</p>
  
  <pre><code>class Item extends Eloquent {
      public function Tags()
      {
          return $this-&gt;belongsToMany('Tag', 'items_has_tags', 'items_id', 'tags_id');
      }
  }
  
  class Tag extends Eloquent {
      public function LearningMaterials()
      {
          return $this-&gt;belongsToMany('LearningMaterial', 'learning_materials_has_tags', 'tags_id', 'learning_materials_id');
      }
  }
  </code></pre>
  
  <p>I want to iterate all tags from my items in my controller:</p>
  
  <pre><code>//get all items
  $all = Item::where('public', '1')-&gt;get();
  
  foreach($allLm as $item){
       $tags = $item-&gt;Tags();
  
       var_dump('will iterate');
  
       foreach($tags as $t){
           var_dump('will not iterate');
       }
  }
  </code></pre>
  
  <p>What is wrong with my code? How can I handle the tags from my items?</p>
  
  <p>FYI: I'm creating a search engine. If the user inserts an input value like "mana", all items with tag "management" should be shown.</p>