title: Laravel getting results from model belongsToMany relationship back to controller
body: <p>I'm using Laravel 5 and Eloquent, I have 3 tables setup:</p>
  
  <pre><code>photos
  +----+---------------+------------------+
  | id |  photo_name   |  photo_location  |
  +----+---------------+------------------+
  |  1 | kittens.jpg   | C:\kittens.jpg   |
  |  2 | puppies.jpg   | C:\puppies.jpg   |
  |  3 | airplanes.jpg | C:\airplanes.jpg |
  |  4 | trains.jpg    | C:\trains.jpg    |
  +----+---------------+------------------+
  
  photo_set (pivot table)
  +------------+----------+
  | set_id     | photo_id |
  +------------+----------+
  |          1 |        1 |
  |          1 |        2 |
  |          2 |        3 |
  |          2 |        4 |
  +------------+----------+
  
  sets
  +----+----------------+
  | id |  description   |
  +----+----------------+
  |  1 | cute animals   |
  |  2 | transportation |
  +----+----------------+
  </code></pre>
  
  <p>I created a <code>belongsToMany</code> relationship in my <code>photos</code> and <code>sets</code> models to link these two together.</p>
  
  <pre><code>class Photo extends Model {
  
      public function sets()
      {
          return $this-&gt;belongsToMany('App\Set');
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class Set extends Model {
  
      public function photos()
      {
          return $this-&gt;belongsToMany('App\Photo');
      }
  
  }
  </code></pre>
  
  <p>However I'm trying to reference the <code>$Sets-&gt;photos()</code> model function in my controller, so that given a set of <code>id=1</code>, I can return the <code>photo_location</code> value for each row <code>[C:\kittens.jpg,C:\puppies.jpg]</code>, but I don't know how to access it..  </p>
  
  <p>Also, I can "sort of" access this information in the view with:</p>
  
  <pre><code>@foreach($sets as $set)
      {{$set-&gt;images}}
  @endforeach
  </code></pre>
  
  <p>but it looks like it only iterates through once and returns a json (?) of the necessary information, though I'm not sure how to parse that to regular HTML either.</p>
  
  <p>So in short, I'm having trouble accessing this data (photo_location) from both the controller and the view</p>