title: Querying Relationships in Laravel 5.2
body: <p>I am having issues trying to query an Eloquent relationship.</p>
  
  <p>I have 2 tables</p>
  
  <p><strong>tbl_deals</strong></p>
  
  <ul>
  <li>id</li>
  <li>deal_id</li>
  <li>merchant_id</li>
  </ul>
  
  <p><strong>tbl_merchants</strong></p>
  
  <ul>
  <li>id</li>
  <li>merchant_id</li>
  <li>merchant_url_text</li>
  </ul>
  
  <p>I defined a deal model as</p>
  
  <pre><code>class deal extends Model
  {
      public function merchant() {
          return $this-&gt;hasOne('App\merchant', 'merchant_id', 'merchant_id');
      }
  }
  </code></pre>
  
  <p>Now, I want to query all deals based where merchant_url_text = a variable in my controller</p>
  
  <p>Here's what I am trying</p>
  
  <pre><code>$deals = deal::with('merchant')-&gt;get(); //Retrieving all the deals with merchants 
  </code></pre>
  
  <p>If I return $deals its giving me all deals with merchant relationship.</p>
  
  <p>How do I constraint the deals by saying where merchant_url_text = $variable</p>
  
  <p>I am trying</p>
  
  <pre><code>return $deals-&gt;where('merchant_url_text', $merchant_url_text)-&gt;get();
  </code></pre>
  
  <p>but it is giving me an error saying :</p>
  
  <blockquote>
    <p>"Missing argument 1 for Illuminate\Support\Collection::get(), called in ..."</p>
  </blockquote>
  
  <p>I tried to lookup the documentation for querying relationships in Laravel Docs. It talks about this example</p>
  
  <pre><code>$user = App\User::find(1);
  
  $user-&gt;posts()-&gt;where('active', 1)-&gt;get();
  </code></pre>
  
  <p>In this case, its trying to get the first user and finding corresponding posts related to the user.</p>
  
  <p>In my case I want to filter from all deals, the deals that have merchant_url_text = a specific variable in my controller.</p>
  
  <p>Any help on how I can achieve this?</p>
  
  <p>Thanks</p>