title: Laravel create a table of relations between models
body: <p>I have a <code>Subscriber</code> model defined as such:</p>
  
  <pre><code>class Subscriber extends \Eloquent {
      public static function scopeConfirmed($query)
      {
          return $query-&gt;where('confirmed', '=', 1);
      }
  
      public function codes()
      {
           return $this-&gt;hasMany('Code');
      }
  }
  </code></pre>
  
  <p>A <code>Meme</code> model:</p>
  
  <pre><code>class Meme extends \Eloquent {
      public function codes() {
          return $this-&gt;hasMany('Code');
      }
  }
  </code></pre>
  
  <p>And a <code>Code</code> model that they are connected through:</p>
  
  <pre><code>class Code extends \Eloquent {
      public function subscriber() {
          return $this-&gt;belongsTo('Subscriber');
      }
      public function meme() {
          return $this-&gt;belongsTo('Meme');
      }
  }
  </code></pre>
  
  <p>What I want to achieve is a table that has <code>Meme</code>'s as columns and <code>Subscribers</code> as rows that would show if a code exists that belongs to a <code>Subscriber</code> and <code>Meme</code>. Using a foreach to achieve that is inefficient and I think there is a way to do that in eloquent.</p>
  
  <pre><code>|-----|Meme 1|Meme 2|Meme 3|
  |Sub 1|  0   |   0  |   1  |
  |Sub 2|  0   |   1  |   1  |
  |Sub 3|  1   |   1  |   0  |
  </code></pre>
  
  <p>Many thanks</p>