title: Laravel 4 and Eloquent: retrieving all records and all related records
body: <p>I have two classes: <code>Artist</code> and <code>Instrument</code>. Each <code>Artist</code> can play one or more <code>Instrument</code>s. And each <code>Instrument</code> can be assigned to one or more <code>Artist</code>s. So, I've set up the following Classes:</p>
  
  <p><strong>Artist.php</strong></p>
  
  <pre><code>public function instruments() {
      return $this-&gt;belongsToMany('App\Models\Instrument');
  }
  </code></pre>
  
  <p><strong>Instrument.php</strong></p>
  
  <pre><code>public function artists() {
      return $this-&gt;belongsToMany('\App\Models\Artist');
  }
  </code></pre>
  
  <p><br>
  Then I have three database tables:</p>
  
  <pre><code>artists: id, firstname, lastname, (timestamps)
  instruments: id, name
  artist_instrument: id, artist_id, instrument_id
  </code></pre>
  
  <p><br>
  I'm able to successfully retrieve a <strong>one</strong> artist and their associated instruments like so:</p>
  
  <p><strong>ArtistController.php</strong></p>
  
  <pre><code>$artist = Artist::find($artist_id);
  $instruments = $artist-&gt;instruments()-&gt;get();
  return \View::make('artists')-&gt;with('artists', $artists)-&gt;with('instruments', $instruments);
  </code></pre>
  
  <p><strong>I have 3 questions:</strong></p>
  
  <ol>
  <li><p>In my view, I can output the <code>$artist</code> like:</p>
  
  <pre><code>{{ $artist-&gt;firstname }}
  </code></pre>
  
  <p>and I can iterate through <code>$instruments</code> like:</p>
  
  <pre><code>@foreach ($instruments as $instrument)
      &lt;h2&gt;{{ $instrument-&gt;name }}&lt;/h2&gt;
  @endforeach
  </code></pre>
  
  <p>but is it possible to iterate over <code>$artist</code> (I know there's only one — see #2) and for each <code>$artist</code> iterate over their <code>$instruments</code>?</p></li>
  <li><p>In my controller, how would I get <strong>all</strong> artists and for each of those their associated instruments with the end goal of iterating through them in my view as described in #1.</p></li>
  <li><p>Is it possible to only retrieve specific columns in the above example of <code>ArtistController.php</code>? I've tried this:</p>
  
  <pre><code>$artist = Artist::where('id', $artist_id)-&gt;get('firstname');
  $instruments = $artist-&gt;instruments()-&gt;get();
  return \View::make('artists')-&gt;with('artists', $artists)-&gt;with('instruments', $instruments);
  </code></pre>
  
  <p>but I get an error saying <code>Collection::instruments()</code> is undefined.</p></li>
  </ol>
  
  <p>I'm assuming there's something not right in my model relationships. I've also tried defining my relationship in <strong>Artist.php</strong> with a <code>hasMany</code> (I think it makes more sense to say "Each Artist hasMany Instruments", but that gives me an error because it's expecting a table named <code>artists_instruments</code> and it's also trying to retrieve columns that wouldn't exists in that table (like <code>name</code>).</p>