mercredi 30 décembre 2015

get sum of all entries by column in laravel

So I have table prices with structure:

+----+--------+
| id | reward |
+----+--------+
| 1  | 721    |
+----+--------+
| 2  | 54     |
+----+--------+
| 3  | 99     |
+----+--------+

and I'm using this method to sum all rewards:

'withdrawals' => \App\Tradeoffer::where('type', 'withdraw')
            ->where('completed', 1)
            ->where('declined', 0)
            ->where('timeout', 0)
            ->where('created_at', '>', (time() - $hours))
            ->sum('reward')

and the response is: 7215499 instead of sum of all entries. Why is that? How to deal with it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire