title: Laravel and Eloquent: Specifying columns in when retrieving related items
body: <p><strong>This is a followup post to:</strong> <a href="https://stackoverflow.com/questions/21735011/laravel-4-and-eloquent-retrieving-all-records-and-all-related-records">Laravel 4 and Eloquent: retrieving all records and all related records</a></p>
  
  <p>The solution given works great:</p>
  
  <pre><code>$artists = Artist::with('instruments')-&gt;get();
  return \View::make('artists')-&gt;withArtists($artists);
  </code></pre>
  
  <p>It also works with just: </p>
  
  <pre><code>$artists = Artist::get();
  </code></pre>
  
  <p>Now I'm trying to specify the exact columns to return for both tables. I've tried using <code>select()</code> in both the statement above and in my Class, like this:</p>
  
  <p><strong>ArtistController.php</strong></p>
  
  <pre><code>$artists = Artist::select('firstname', 'lastname', 'instruments.name')-&gt;get();
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>$artists = Artist::with(array('instruments' =&gt; function($query) {
      $query-&gt;select('name');
  }))-&gt;get();
  </code></pre>
  
  <p>(as suggested <a href="https://stackoverflow.com/questions/19852927/get-specific-columns-using-with-function-in-laravel-eloquent"><strong>here</strong></a> and while this doesn't throw an error, it also doesn't limit the columns to only those specified)</p>
  
  <p>or in <strong>Artist.php</strong>:</p>
  
  <pre><code>return $this-&gt;belongsToMany('App\Models\Instrument')-&gt;select(['name']);
  </code></pre>
  
  <p>How would I go about getting <em>just</em> the <code>firstname</code> and <code>lastname</code> column from the <code>artists</code> table and the <code>name</code> column from <code>instruments</code> table?</p>