title: Laravel Eloquent: filtering model by relation table
body: <p>I have <code>places</code> and <code>locations</code> tables.
  Place could have many locations. Location belongs to Place.</p>
  
  <p>Place:
  <code>id</code>
  <code>title</code></p>
  
  <p>Location:
  <code>id</code>
  <code>place_id</code>
  <code>floor</code>
  <code>lat</code>
  <code>lon</code></p>
  
  <pre><code>class Location extends Model {
  
      public function place()
      {
          return $this-&gt;belongsTo('App\Place');
      }
  
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>class Place extends Model {
  
      public function locations()
      {
          return $this-&gt;hasMany('App\Location');
      }
  
  }
  </code></pre>
  
  <p>And i need to find places, that belongs only to 1st floor. <code>select * from places inner join locations on places.id = locations.place_id where locations.floor = 1</code></p>
  
  <p>How does it should be done in Eloquent?</p>
  
  <p>Is something similar to
  <code>Place::where('locations.floor', '=', 1)-&gt;get()</code> exists?</p>
  
  <p>Yes, i know there is <code>whereHas</code>:</p>
  
  <pre><code>Place::whereHas('locations', function($q)
  {
      $q-&gt;where('floor', '=', 1);
  })-&gt;get()
  </code></pre>
  
  <p>but it generates a bit complex query with counts:</p>
  
  <pre><code>select * from `places` where (select count(*) from `locations` where `locations`.`place_id` = `places`.`id` and `floor` = '1') &gt;= 1
  </code></pre>