Laravel Sum of relation
问题 I want to return the sum of "amount" from my payments table. There can be many payments for one invoice. The below "->sum('amount') does not work, it returns: Call to a member function addEagerConstraints() on a non-object. How to return the sum of all payments for each invoice in my relation? Invoices Model: class Invoices extends Eloquent { public function payments() { return $this->hasMany('Payments')->sum('amount'); } } Expenses Model: class Payments extends Eloquent { public function