title: laravel filter the results based upon attributes
body: <p>I have one main tabel called "motors" and their attributes i am saving in the sub table "motor_attributes". The atributes are dynamic and they can hold any id and value. 
   The relationship is one to many relationship. 
  The problem is i cant search any of the attribute. It gives me the same parent table items 
  "enteries". </p>
  
  <p>I want to make it more clear. Every time it gives  me 6 enteries. Even though if i change the value of the  $request->get('body_condition'). manually. because its query string. 
  And i want to filter motors best upon these attributes.
  Any help will be appreciated.
  It just hide the attributes not the main Advertisement.
  Any help will be appreciated. 
  Thanks in Advance</p>
  
  <p>```````````</p>
  
  <pre><code>        $perPage = 20;
          $motorQuery = Motor::with(['advertisementPhotos', 'country', 'city', 'customer.dealer','favouriteAd', 'adAttributes' =&gt; function ($query) use ($request){
  
               // dd($request-&gt;get('body_condition'));
               $query-&gt;where('integer_value',$request-&gt;get('body_condition'));
               $query-&gt;with('attribute');
               $query-&gt;with('adAttributeValue');
               $query-&gt;where('show_listing_page',1);
          //;
          //  return $query-&gt;take(2);
  
            }])
          -&gt;where('status', 1)
          -&gt;where('date_expiry', '&gt;=', date('Y-m-d') . ' 00:00:00');
  
  
      if (request()-&gt;filled('city')) {
          $motorQuery-&gt;where('city', request()-&gt;get('city'));
      }
      if (request()-&gt;filled('keywords')) {
          $motorQuery-&gt;where('title', 'like', '%' . request()-&gt;get('keywords') . '%');
      }
      if (request()-&gt;filled('from_price')) {
          $motorQuery-&gt;where('price', '&gt;=', request()-&gt;get('from_price') );
      }
      if (request()-&gt;filled('to_price')) {
          $motorQuery-&gt;where('price', '&lt;=', request()-&gt;get('to_price') );
      }
  
  
      if (request()-&gt;hasCookie('country')) {
          $motorQuery-&gt;where('country', request()-&gt;cookie('country')-&gt;first()-&gt;id);
      }
  
      $data['allMotors'] =  $allMotors = $motorQuery-&gt;orderBy('featured', 'desc')-&gt;orderBy('date_posted', 'desc')-&gt;paginate($perPage);
  </code></pre>
  
  <p>```</p>