I am working on reports where I have been trying to get the total sum from individual sums, I am writing this on using Laravel Eloquent relations.
My code:
$MyModelLog = \App\Models\MyModelName::select('id', 'created_by', 'total_count', 'type')->whereIn('created_by', $arrUserids)->get();
$MyModelLog = $MyModelLog->groupBy('created_by')->map(function ($row) {
$countsArr['hot_list'] = [];
$countsArr['job_share'] = [];
$countsArr['hot_list']['shared_count'] = count($row->where('type', 1));
$countsArr['hot_list']['sent_count'] = $row->where('type', 1)->sum('total_count');
$countsArr['job_share']['shared_count'] = count($row->where('type', 2));
$countsArr['job_share']['sent_count'] = $row->where('type', 2)->sum('total_count');
return $countsArr;
});
$MyModelLogsArr = $MyModelLog->toArray();
My Problem is I want to get/calculate the sum of all the $countsArr['hot_list']['shared_count'] and $countsArr['hot_list']['sent_count'] similarly for $countsArr['job_share']['shared_count'] & $countsArr['job_share']['sent_count']
Any help?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire