title: Laravel adding custom attribute to where clause
body: <p>I have a <code>mutator</code> that calculate the product existing quantity by:</p>
  
  <p><strong><em>summing the product credit and minus it from the sold credit</em></strong>.</p>
  
  <pre><code>public function getReportTotalQuantityAttribute() {
      // GET IMPORT INVOICE SUM
      $import_invoices_sum = $this -&gt; credits -&gt; sum('quantity');
  
      // GET EXPORT INVOICE SUM
      $export_invoices_sum = $this -&gt; sold -&gt; sum('quantity');
  
      // CALCULATE THE SUM
      return $import_invoices_sum - $export_invoices_sum;
  }
  </code></pre>
  
  <p>This <code>mutator</code> works fine and return the actually product quantity as <code>report_total_quantity</code> attribute whenever I call the model.</p>
  
  <h1>What I am trying to do:</h1>
  
  <p>I am trying to get the product <code>where('report_total_quantity', '&gt;', 0)</code>.</p>
  
  <h1>What I have tried:</h1>
  
  <pre><code>$condition_queries = Product::withCreditsAndWarehouses() -&gt; where('report_total_quantity', '&gt;', 0);
  </code></pre>
  
  <p>But I am getting error say <code>Unknown column 'report_total_quantity'</code>. And this is logical since I don't have this column but I append it using <code>$append</code> and <code>mutator</code>.</p>
  
  <h1>What I searched and found:</h1>
  
  <p>I have found something called <code>filters</code> but I don't think it is good solution since I am using <code>paginate(10)</code> and like that I will return <code>10</code> values and filter them.</p>
  
  <p>Also I have many other conditions and filter is not working good for me.</p>