title: Has one through Laravel Eloquent
body: <p>I have three tables <code>garages</code>, <code>cars</code>, <code>securities</code>.</p>
  
  <p>The securities are the ones that is keeping one car safe, you can have more than one security, but a single security can keep only one car safe. The garage is where the car is and the securities are as well.</p>
  
  <p>What I want is to list all the securities and know the name of the garage that he is. The problem is that <code>securities</code> doesn't have a column containing the id of the garage, only the id of the car that he is keeping safe, but car has the id of the garage.</p>
  
  <p>Laravel Eloquent has a method called <code>hasManyThrough</code>, but <code>securities</code> has one <code>garage</code> through <code>cars</code> only.</p>
  
  <p>Here is the tables:</p>
  
  <p>garages table:</p>
  
  <pre><code>-----------------------------------
  |garage_id|garage_name|garage_size|
  -----------------------------------
  |        1|   Garage 1|        200|
  -----------------------------------
  |        2|   Garage 2|        400|
  -----------------------------------
  </code></pre>
  
  <p>cars table:</p>
  
  <pre><code>---------------------------
  |car_id|car_name|garage_id|
  ---------------------------
  |     1|   Car 1|        1|
  ---------------------------
  |     2|   Car 2|        1|
  ---------------------------
  |     3|   Car 3|        2|
  ---------------------------
  </code></pre>
  
  <p>securities table:</p>
  
  <pre><code>----------------------------------
  |security_id|security_name|car_id|
  ----------------------------------
  |          1|  Security 1|      1|
  ----------------------------------
  |          2|  Security 2|      1|
  ----------------------------------
  |          3|  Security 3|      2|
  ----------------------------------
  |          4|  Security 4|      3|
  ----------------------------------
  </code></pre>
  
  <p>The output must to be:</p>
  
  <pre><code>Security 1 is on Garage 1
  Security 2 is on Garage 1
  Security 3 is on Garage 1
  Security 4 is on Garage 2
  </code></pre>
  
  <p>And I have the models:</p>
  
  <p>The code is to list the garages, but I want to make similar but to list the securities (just for you to have an idea of how the structure is).</p>
  
  <pre><code>$garages = Garages::with(['cars', 'securities'])-&gt;get();
  
  $garages-&gt;transform(function($garages) {
      return array(
          'garage_name'      =&gt; $garage-&gt;garage_name,
          'count_cars'       =&gt; $garage-&gt;cars-&gt;count(),
          'count_securities' =&gt; $garage-&gt;securities-&gt;count(),
     );
  });
  
  class Garages extends Eloquent
  {
      public function cars()
      {
          return $this-&gt;hasMany('cars');
      }
  
      public function securities()
      {
          return $this-&gt;hasMany('securities');
      }
  }
  
  class Cars extends Eloquent
  {
  }
  
  class Securities extends Eloquent
  {
  }
  </code></pre>
  
  <p>And just to make an emphasis again: <strong>I want to have the name of the garage related to the car that the security is keeping safe.</strong></p>
  
  <p>Just to make it even easier to understand, if I do this:</p>
  
  <pre><code>$securities = Securities::with(['cars'])-&gt;get();
  
  class Securities extends Eloquent
  {
      public function cars()
      {
          return $this-&gt;hasOne('cars');
      }
  }
  </code></pre>
  
  <p>I will get only the <code>garage_id</code> from <code>cars</code> table as relations. What I really want is the name of the garage.</p>
  
  <pre><code>[relations:protected] =&gt; Array
      (
          [cars] =&gt; Cars Object
              (
                  ...
                  [attributes:protected] =&gt; Array
                      (
                          ...
                          [car_name] =&gt; Car 1
                          [garage_id] =&gt; 1
                          ...
  </code></pre>