sum

Laravel Sum of relation

人盡茶涼 提交于 2020-11-29 19:15:27
问题 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

Laravel Sum of relation

天涯浪子 提交于 2020-11-29 19:15:08
问题 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

Laravel Sum of relation

家住魔仙堡 提交于 2020-11-29 19:13:57
问题 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

Laravel Sum of relation

时光毁灭记忆、已成空白 提交于 2020-11-29 19:13:23
问题 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

Sum elements of a vector beween zeros in R

╄→гoц情女王★ 提交于 2020-11-29 09:48:08
问题 I have a vector with zeros and positives numbers. I would simply like to sum the numbers that are between the zeros. A simple example: x <- c(0,0,0,0,0,1,23,24,54,12,1,23,0,0,0,0,1,23,56,76,0,1,13) That is, I want to sum the elements 1,23,24,54,12,1,23 , 1,23,56,76 and 1,13 . My desired output would therefore be: 138 , 156 and 14 . I found this really similar question but it is on Python: Sum elements of a list between zeros in Python Thanks. 回答1: We can use tapply , creating groups with