title: Constrain child relation by current parent id laravel
body: <p>I am having four tables which are;</p>
  <ul>
  <li>report: fields; id, name,programme_id</li>
  <li>programme: fields; id, name</li>
  <li>weights: fields; id, programme_id, attribute</li>
  <li>compliance: fields: id,weight_id,report_id,compliance_id</li>
  </ul>
  <p>A report belongs to a programme, a programme has many weights and each weights belongs to many compliance compliance what i want is getting all compliance under each weight for a given report.</p>
  <p>Here is what i have tried;</p>
  <pre><code>public function allReports(): Builder
      {
          return static::with(['programme.weights.compliance'=&gt;function($q){
              $q-&gt;whereColumn('report_id','reports.id');
          }]);
      }
  </code></pre>
  <p>but i keep getting the response:</p>
  <blockquote>
  <p><code>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'reports.id' in 'where clause' (SQL: select </code>quality_compliances<code>.*, </code>report_quality_compliances<code>.</code>programme_weight_id<code>as</code>pivot_programme_weight_id<code>, </code>report_quality_compliances<code>.</code>quality_compliance_id<code>as</code>pivot_quality_compliance_id<code>, </code>report_quality_compliances<code>.</code>percentage<code>as</code>pivot_percentage<code>, </code>report_quality_compliances<code>.</code>report_id<code>as</code>pivot_report_id<code>from</code>quality_compliances<code>inner join</code>report_quality_compliances<code>on</code>quality_compliances<code>.</code>id<code>=</code>report_quality_compliances<code>.</code>quality_compliance_id<code>where</code>report_quality_compliances<code>.</code>programme_weight_id<code>in (53, 54, 55, 56, 57, 58, 59, 60, 61) and</code>report_id<code>=</code>reports<code>.</code>id<code>and</code>quality_compliances<code>.</code>deleted_at<code> is null)&quot;,</code></p>
  </blockquote>