title: Laravel: How do I create a custom pivot model?
body: <p>I'm working on a project that has a many to many relationship between <code>User</code> and <code>Club</code>. This relationship works and I can get the respective objects with: <code>$user-&gt;clubs</code>. The pivot table I've named <code>memberships</code>. I can get the pivot data with <code>$club-&gt;pivot</code>. Foreign keys are defined for the <code>memberships</code> table in migrations.</p>
  
  <p>However, I'd like the pivot table to be represented by a model so that I can easily update attributes of <code>Membership</code> such as role (Or even add a <code>Role</code> model to <code>Membership</code>!) or <code>status</code>.</p>
  
  <p>I've looked at "<a href="http://laravel.com/docs/eloquent#working-with-pivot-tables" rel="noreferrer">Defining A Custom Pivot Model</a>" in the docs, but what it says doesn't work for me, I get:</p>
  
  <p><code>
  ErrorException
  Argument 1 passed to Illuminate\Database\Eloquent\Model::__construct() must be of the type array, object given
  </code></p>
  
  <p>I've also looked at <a href="https://github.com/laravel/framework/issues/2093#issuecomment-28689244" rel="noreferrer">this description</a> of how to do it, but it's more or less the same as above. </p>
  
  <p><code>Membership</code> model:</p>
  
  <pre><code>class Membership extends Eloquent {
  
  protected $table = 'memberships';
  
  public function user()
  {
      return $this-&gt;belongsTo('User');
  }
  
  public function club()
  {
      return $this-&gt;belongsTo('Club');
  }
  }
  </code></pre>
  
  <p>Has anyone done this before?</p>