Hi.
Im at another learning point where i want to try and group an elequent query by user_id and date, but then have it display correctly in blade. Im completely new to grouping and ive tried a few things from the laravel docs and google, but its not quite doing what i want. So hoping the awesome laravel community can help me once again :) ...
I have database table with a lot of rows (which i need to chunk i think from what i read) and each row has an user id, transaction_type and transaction_date.
I want to grab every transaction within the date range that i provide and then group it by the user_id.
I have the groupBy working (bar the chunking), but the next spanner in the works is that there is a transaction type where i need to do a sum of adding all the rows that has a transaction_type of DB and the same for CR and then subtract the 2 from each other.
And then of course i need to display this on a view as User x has a balance of £xx
The database is unfortunately something ive taken over and im now working to try and breakup to put less strain on the query as the rows will grow (now at 90,000 rows).
Heres my controller ::
$ledgers = Ledger::select('user_id', 'transaction_amount', 'transaction_date', 'transaction_type')
->whereBetween('transaction_date', ['2018-01-01', Carbon::now()->toDateString()])
->get()
->groupBy(function($date) {
return Carbon::parse($date->transaction_date)->format('m');
});
Any help would be great.
Thank you