title: Laravel 4 Eloquent ORM: How to update a pivot table entry that has composite primary keys
body: <p>I have a many-to-many relationship like so:</p>
  
  <pre><code>user
   - user_id
  
  user_blocks
   - blocker_user_id
   - blocked_user_id
   - unblocked (Timestamp)
  </code></pre>
  
  <p>Where blocker and blocked_user_id are a composite primary key, both existing as a foreign key to the user table's user_id.  Both tables are InnoDB.</p>
  
  <p>When I attempt to do the following:</p>
  
  <pre><code>$user = User::find(1)
  $blocked_user = $user-&gt;blocked()-&gt;where('blocked_user_id', 2)-&gt;first();
  
  $blocked_user-&gt;unblocked = User::freshTimestamp();
  $blocked_user-&gt;save();
  </code></pre>
  
  <p>It seems to think I wish to update a column in the user table, rather than the user_blocks table. This is simply an sql error where the user table is attempting to be updated with the non-existent column <code>unblocked</code>.</p>
  
  <p>I've tried adding <code>-&gt;pivot</code> and <code>-&gt;pivot()</code> to the assignment for $blocked_user in the example. The first gives me an error in Eloquent\Model::performUpdate, <code>Call to a member function update() on a non-object</code> and the latter gives me <code>call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Database\Query\Builder' does not have a method 'pivot'</code> in Eloquent\Builder::__call. </p>
  
  <p>The model for the user table defines the relationship to itself as:</p>
  
  <pre><code>public function blocked() {
      return $this-&gt;belongsToMany(
          'User', 
          'user_blocks', 
          'blocker_user_id', 
          'blocked_user_id'
      )-&gt;withPivot('unblocked');
  }
  </code></pre>
  
  <p>There is no model for the user_blocks table as I do not know how to define an Eloquent model with a composite primary key (I've searched everywhere and that doesn't seem to be a question anyone has asked).</p>
  
  <p>I realize the schema is less than optimized for Eloquent, but this is grafting eloquent onto a Codeigniter project with a pre-established schema. An otherwise pleasant experience over using Codeigniter models.</p>