How to transpose from row to column used laravel [duplicate]
Solution 1:
Not having your tables it will be a bit hard, but I hope that this will give you a path to what you want to achieve, it might be luck that it will work from the first shot :)
DB::table('statement_versions as sv')
->select([
'name',
DB::raw('sum(balance) as total')
])
->join('statements as s', 'sv.statement_id', '=', 's.id')
->join('accounts as a', 's.account_id', '=', 'a.id')
->groupBy('name');