title: How to order by using appended attribute in Laravel
body: <p>I created an appends attribute in Laravel Model, from the code below.</p>
  
  <pre><code>    protected $appends = array('total'=&gt;'');
  </code></pre>
  
  <p>And I set the returned value.</p>
  
  <pre><code>    public function getTotalAttribute(){
             return ProductPart::where('product_id',$this-&gt;id)-&gt;count();
      }
  </code></pre>
  
  <p>Then I want to order records from database by using <code>total</code> attribute</p>
  
  <p>I tried to use <code>Product::orderBy('total','desc')-&gt;get()</code> but it didn't work.</p>
  
  <p>Does anybody has some suggestions to this?</p>