title: How to set Eloquent relationship belongsTo THROUGH another model in Laravel?
body: <p>I have a model Listing that inherits through its belongsTo('Model') relationship should inherently belong to the Manufacturer that its corresponding Model belongs to.</p>
  
  <p>Here's from my Listing model:</p>
  
  <pre><code>    public function model()
      {
          return $this-&gt;belongsTo('Model', 'model_id');
      }
  
      public function manufacturer()
      {
          return $this-&gt;belongsTo('Manufacturer', 'models.manufacturer_id');
          /*
          $manufacturer_id = $this-&gt;model-&gt;manufacturer_id;
          return Manufacturer::find($manufacturer_id)-&gt;name;*/
      }
  </code></pre>
  
  <p>and my Manufacturer model:</p>
  
  <pre><code>public function listings()
  {
      return $this-&gt;hasManyThrough('Listing', 'Model', 'manufacturer_id', 'model_id');
  }
  
  public function models()
  {
      return $this-&gt;hasMany('Model', 'manufacturer_id');
  }
  </code></pre>
  
  <p>I am able to echo $listing->model->name in a view, but not $listing->manufacturer->name. That throws an error. I tried the commented out 2 lines in the Listing model just to get the effect so then I could echo $listing->manufacturer() and that would work, but that doesn't properly establish their relationship. How do I do this? Thanks.</p>
  
  <p>Revised Listing model (thanks to answerer):</p>
  
  <pre><code>    public function model()
      {
          return $this-&gt;belongsTo('Model', 'model_id');
      }
  
      public function manufacturer()
      {
          return $this-&gt;belongsTo('Model', 'model_id')
              -&gt;join('manufacturers', 'manufacturers.id', '=', 'models.manufacturer_id');
      }
  </code></pre>