title: Laravel relationship sum on appends attribute
body: <p>i have two model</p>
  
  <p>this is my <strong>material</strong> model:</p>
  
  <pre><code>&lt;?php
  namespace App;
  use Illuminate\Database\Eloquent\Model;
  class material extends Model
  {
      protected $fillable = ['proposal_id','thickness','width','length','qty','description'];
      public $timestamps = false;
      protected $appends = ['total'];
      public function proposal()
      {
          return $this-&gt;belongsTo(proposal::class);
      }
      public function getTotalAttribute()
      {
          return $this-&gt;qty * $this-&gt;price;
      }
  }
  </code></pre>
  
  <p>this is my <strong>proposal</strong> model:</p>
  
  <pre><code>&lt;?php
  namespace App;
  use Illuminate\Database\Eloquent\Model;
  class proposal extends Model
  {
      public function materials()
      {
          return $this-&gt;hasMany(material::class);
      }
  }
  </code></pre>
  
  <p>i'm trying to get all proposal with summary from total attribute which is an appended attribute.</p>
  
  <p>This is not working:</p>
  
  <pre><code>\App\proposal::with(['materials'=&gt;function($q){
      $q-&gt;sum('total');
      }])
      -&gt;get();
  </code></pre>
  
  <p>how to do it properly?
  thank you</p>