I'm using laravel framework, very newbie with it. I have multiple records in my php application, something like this:
"[{"balance":20,"account_number":"1"},
{"balance":80,"account_number":"1"}
{"balance":20,"account_number":"2"}]"
I need to SUM the total balance of account_number.
So it should be:
account_number1 - balance 100
account_number2 - balance 20
I have tried
>>> $orders = DB::table('demo_trades')->select('balance', DB::raw('SUM(balance)'))->groupBy('account_number')->get()->toJson();
How I can do it?
DB::table('demo_trades')->sum('balance')->groupBy('account_number')->get()->toJson();