title: Add condition base on parent's parent data in laravel
body: <p>I have a problem converting query to Laravel Eloquent.
  This is the query:</p>
  
  <pre><code>SELECT cat.id,
         reg.title AS region_title,
         reg.region_code,
         catlang.title,
         catlang.description,
         cat.status
  FROM categories AS ca
  JOIN regions As reg
        ON cat.region_id = reg.id
  JOIN category_language_region As catlang
        ON cat.id = catlang.category_id
            AND reg.language_id = catlang.language_id;
  </code></pre>
  
  <p>That is working in Postgres and as you can see, I added additional condition for joining category_language_region <code>reg.language_id = catlang.language_id</code>. I'm stuck on converting it to Laravel Eloquent Builder.</p>
  
  <p>This is the schema for it</p>
  
  <ul>
  <li>Table Language: id, code </li>
  <li>Table Region: id, code, language_id</li>
  <li>Table Category: id, status, region_id</li>
  <li>Table Category Language Region: id, title, category_id, language_id</li>
  </ul>
  
  <p>This is what I tried</p>
  
  <pre><code>$results = Category::with([
      'region' =&gt; function($query){
          $query-&gt;select('title', 'id', 'region_code', 'language_id');
      },
      'categoryLanguages'
  ])-&gt;select(['categories.*'])
  -&gt;whereIn('region_id', $region_ids);
  </code></pre>
  
  <p>But it returns all category language region. I need add to condition to select only <code>category_language_region.language_id</code> equal to selected <code>region.language_id</code>.</p>