title: Relationships and where clauses?
body: <p>I have the following tables:</p>
  
  <pre><code>**galleries**
  
  id
  location
  open_to_public
  
  **pictures**
  id
  title
  published
  
  **gallery_picture**
  gallery_id
  picture_id
  </code></pre>
  
  <p>Here's my model for galleries:</p>
  
  <pre><code>class Galleries extends Eloquent {
  
  protected $table = 'galleries';
  
  public function pictures(){
  
      return $this-&gt;belongsToMany('pictures', 'gallery_picture', 'gallery_id', 'picture_id');
  
  }
  </code></pre>
  
  <p>I'm trying to select a gallery (id, location) and get it's related pictures (id, title).</p>
  
  <p>To start with I've tried this but it seems to return a huge amount of data, im not sure if I'm doing it correct?</p>
  
  <pre><code>$this-&gt;mGalleries = new Galleries;
  return $this-&gt;mGalleries-&gt;pictures();
  </code></pre>
  
  <p>What I want to also do is add some constraints to the query, I understand I can do it like:</p>
  
  <pre><code>public function scopePublic()
  {
          return $query-&gt;where('open_to_public','=',1);
  }
  </code></pre>
  
  <p>Then:
      return $this->mGalleries->pictures()->public();</p>
  
  <p>But I have yet to implement this correctly. Could someone point me in the right direction.</p>
  
  <p>I want to get gallery.id, gallery.location and all of that galleries pictures where gallery.open_to_public = 1 and to only get pictures that published = 1.</p>
  
  <p>Also I would like to get all of the galleries that are relevant to the above conditions and not just a single one.</p>