title: Laravel 4 eloquent pivot table
body: <p>I have three tables: users, items and user_items. A user has many items and a item belongs to many users.</p>
  
  <p>The tables:</p>
  
  <pre><code>Users
  id
  username
  password
  
  Items
  id
  name
  equipable
  
  User_items
  id
  user_id
  item_id
  equipped
  </code></pre>
  
  <p>The models:</p>
  
  <pre><code>class User extends Eloquent {
       public function items()
       {
           return $this-&gt;belongsToMany('Item', 'user_items')
                     -&gt;withPivot('equipped');
       } 
  }
  
  class Item extends Eloquent {
      public function users()
      {
           return $this-&gt;belongsToMany('User', 'user_items');
      }
  }
  </code></pre>
  
  <p>In the pivot (user_items) table I've a very important column named "equipped".</p>
  
  <p>I've a form where users can equip, unequip and throw items. This form has a hidden field with the pivot (user_items) table row id. So, when a user tries to equip an item, the system checks if the item is equipable.</p>
  
  <p>So, I want a object with the pivot data and the item data, based on item_id from the pivot table, I can send to the handler (where all logic is handled). </p>
  
  <p>So what I've to do is to first access the pivot table and then access the item table.</p>
  
  <p>Something like this (does not work):</p>
  
  <pre><code>$item = User::find(1)-&gt;items-&gt;pivot-&gt;find(1);
  </code></pre>
  
  <p>Is this possible to do?</p>