title: I many-to-many relationship, get ID of pivot table
body: <p>I have the following models in a many-to-many relationship:</p>
  
  <pre><code>class Event extends Model
  {
      public function positions() {
          return $this-&gt;belongsToMany(Position::class, 'position_events');
      }
  }
  
  class Position extends Model
  {
      public function events() {
          return $this-&gt;belongsToMany(Event::class, 'position_events');
      }
  }
  
  class PositionEvent extends Model
  {
      public function position() {
          return $this-&gt;hasOne(Position::class, 'id', 'position_id');
      }
  
      public function event() {
          return $this-&gt;hasOne(Event::class, 'id', 'event_id');
      }
  }
  </code></pre>
  
  <p>The <code>position_events</code> table looks like:</p>
  
  <pre><code>id | event_id | position_id
  </code></pre>
  
  <p>If <code>$event</code> is an instance of <code>Event</code>, I can get the related positions as:</p>
  
  <pre><code>$event-&gt;positions;
  </code></pre>
  
  <p>This gives me something like the following for each related Position:</p>
  
  <pre><code>{"id":4,"name":"Striker","created_at":"2019-04-02 16:19:57","updated_at":"2019-04-02 16:19:57","pivot":{"event_id":27,"position_id":4}}  
  </code></pre>
  
  <p>Notice the <code>pivot</code> element. It only has <code>event_id</code> and <code>position_id</code> as properties, these are columns from the <code>position_events</code> table. How do I get it to have the <code>id</code> column from that table as well?</p>