title: Laravel belongsToMany to return specific columns only
body: <p>So I have a many to many relationship between Users and Photos via the pivot table <code>user_photo</code>. I use <code>belongsToMany('Photo')</code> in my User model. However the trouble here is that I have a dozen columns in my Photo table most I don't need (especially during a json response). So an example would be:</p>
  
  <pre><code>//Grab user #987's photos:
  User::with('photos')-&gt;find(987);
  //json output:
  {
    id: 987,
    name: "John Appleseed",
    photos: {
      id: 5435433,
      date: ...,
      name: 'feelsgoodman.jpg',
      ....// other columns that I don't need
    }
  }
  </code></pre>
  
  <p>Is it possible to modify this method such that <code>Photos</code> model will only return the accepted columns (say specified by an array <code>['name', 'date']</code>)?</p>
  
  <p><strong>User.php</strong></p>
  
  <pre><code>public function photos()
  {
    return $this-&gt;belongsToMany('Photo');
  }
  </code></pre>
  
  <p>Note: I only want to select specific columns when doing a <code>User-&gt;belongsToMany-&gt;Photo</code> only. When doing something like <code>Photo::all()</code>, yes I would want all the columns as normal.</p>
  
  <p>EDIT: I've tried <a href="https://stackoverflow.com/questions/19852927/get-specific-columns-using-with-function-in-laravel-eloquent?rq=1">Get specific columns using &quot;with()&quot; function in Laravel Eloquent</a> but the columns are still being selected. Also <a href="https://github.com/laravel/laravel/issues/2306" rel="nofollow noreferrer">https://github.com/laravel/laravel/issues/2306</a></p>