title: Laravel 5 - Eloquent JOIN confusion
body: <p>I have two simple tables, cats and breeds:</p>
  
  <pre><code>mysql&gt; select * from cats;
  +----+--------+---------------+----------+---------------------+---------------------+
  | id | name   | date_of_birth | breed_id | created_at          | updated_at          |
  +----+--------+---------------+----------+---------------------+---------------------+
  |  1 | Rita   | 2008-07-06    |        1 | 2015-05-09 20:40:49 | 2015-05-09 20:50:20 |
  |  2 | Muni   | 1992-05-15    |        3 | 2015-05-09 20:50:54 | 2015-05-09 20:50:54 |
  |  3 | Hector | 2005-01-23    |        4 | 2015-05-09 21:08:23 | 2015-05-09 21:08:23 |
  +----+--------+---------------+----------+---------------------+---------------------+
  3 rows in set (0.00 sec)
  
  mysql&gt; select * from breeds;
  +----+------------+
  | id | name       |
  +----+------------+
  |  1 | Domestic   |
  |  2 | Persian    |
  |  3 | Siamese    |
  |  4 | Abyssinian |
  +----+------------+
  4 rows in set (0.00 sec)
  </code></pre>
  
  <p>All I want to do is get a list of the cats that are of a certain breed. In the cats table, breed_id is a FK that points to the PK of the breeds table. The example code in my book which is supposed to return a view with all cats of a specific breed returns no results:</p>
  
  <p>The url I am trying is /cats/breeds/Domestic</p>
  
  <p>The view that is generated uses this logic in the routes.php file:</p>
  
  <pre><code>Route::get('cats/breeds/{name}', function($name)
  {
      $cats = Furbook\Cat::with('breeds')
          -&gt;whereName($name)
          -&gt;get();
  dd($cats);
  });
  </code></pre>
  
  <p>When I dd($cats) I get zero results even though I have a cat with a domestic breed_id of 1. What have I done wrong here?</p>
  
  <p>EDIT:</p>
  
  <p>I can get it to work with the following hacky code, which first gets the id from the breeds table by querying against the name field, then queries the cats table with that id:</p>
  
  <pre><code>$breed = Furbook\Breed::whereName($name)-&gt;get();
  $id = $breed[0]['attributes']['id'];
  $cats = Furbook\Cat::whereId($id)-&gt;get();
  </code></pre>
  
  <p>How do I make this into one Eloquent query? I see no examples for this kind of query on the Laravel site.</p>
  
  <p>For more information this is how the models look:</p>
  
  <pre><code>class Breed extends Model {
  
      public $timestamps = false;
  
      public function cats()
      {
          return $this-&gt;hasMany('Furbook\Breed');
      }
  
  }
  
  class Cat extends Model {
  
      protected $fillable = [
          'name',
          'date_of_birth',
          'breed_id',
      ];
  
      public function breed()
      {
          return $this-&gt;belongsTo('Furbook\Breed');
      }
  
  }
  </code></pre>