Laravel - Has Many Through
<p>I'm trying to write a DB Query with Laravel 5.3's <a href="https://laravel.com/docs/5.3/eloquent-relationships#has-many-through" rel="nofollow">Has Many Through option</a></p>

<p>My DB Tables are layed out as follows :</p>

<p><a href="http://sqlfiddle.com/#!9/a9c9af" rel="nofollow">http://sqlfiddle.com/#!9/a9c9af</a></p>

<p>The tables are :</p>

<p>companies
company_offers
offers</p>

<p>In my Model I have the following setup :</p>

<pre><code>public function offers()
    {
        return $this-&gt;hasManyThrough(
            'App\Offers', 'App\CompanyOffers',
            'company_offer_id', 'offer_id'
        );
    }
</code></pre>

<p>When I try to run the following line of code :</p>

<pre><code>return $this-&gt;whereHas('offers', function($query) use ($offer_id)
        {
            return $query-&gt;whereIn('offer_id', $offer_id);
        });
</code></pre>

<p>I get the Error :</p>

<blockquote>
  <p>Integrity constraint violation: 1052 Column 'offer_id' in where clause
  is ambiguous</p>
</blockquote>

<p>How do I go about correcting this and getting the relationship right?</p>

<p>I need to get the <strong>offer title &amp; offer icon</strong> for my frontend view.</p>

<p>Hope this makes sense and someone can help me.</p>

<p>Thanks</p>