title: How to select based on child of child relationship using Laravel Eloquent?
body: <p>I have the following tables structure for merchants &amp; dynamic filters</p>
  <p><code>Merchant Table</code></p>
  <pre><code>id | name 
  -------------------------
   1 | Food Supplier  
  </code></pre>
  <p><code>Filters</code></p>
  <pre><code>id | name 
  -------------------------
   1 | Service Area
   2 | Service Cost
  </code></pre>
  <p><code>Filter Values</code></p>
  <pre><code>id | filter_id | value
  -------------------------
   1 | 1         | Africa
   2 | 1         | Europe
   3 | 2         | 2000-4000
   4 | 2         | 4000-6000
  </code></pre>
  <p><code>Merchant Filter Values</code></p>
  <pre><code>id | filter_id | value_id | merchant_id
  ----------------------------------------
   1 | 1         | 1        | 1
   2 | 1         | 2        | 1
   3 | 2         | 4        | 1
  </code></pre>
  <p>I run the following query to search through merchants using filters:</p>
  <pre><code> select * 
      from `merchants`
      where `name` LIKE &quot;%search_term%&quot;
      and exists (
          select * 
          from `filter_values` 
          inner join `merchant_filter_values`
          on `filter_values`.`id` = `merchant_filter_values`.`value_id` 
          where `merchants`.`id` = `merchant_filter_values`.`merchant_id`
          and (`filter_values`.`id` = 1 and filter_values.filter_id = 2)
          or (`filter_values`.`id` = 2 and filter_values.filter_id = 3)
          or etc.
      )
  </code></pre>
  <p>The query works fine, and returns results as expected, the only problem that it is not eloquent so it doesn't return appends variables/functions from the model for example that featured_img_url is not returned in the result:</p>
  <pre><code>protected $appends = array('featured_img_url');
  public function getFeaturedImgUrlAttribute()
      {
          $img_path = Config::get('app.asset_url') . &quot;/merchants/featured/&quot; . $this-&gt;id . &quot;.&quot;;
          return $img_path . $this-&gt;featured_image_ext . $this-&gt;getLastUpdatedUrl();
      }
  </code></pre>
  <p>The question is, how do I write such query using laravel eloquent?</p>