How can I using same query and just change the where statement like this:
$query = Transaction::ofBranch($this->merchant_id)->where(DB::raw('MONTH(created_at)'), Carbon::now()->subMonths($value)->format('m'));
$count = $query->count();
$total_paid = $query->where('status',1)->sum('amount');
$total_unpaid = $query->where('status',0)->sum('amount');
I got all result except $total_unpaid.
When I check, it appears the query has been replaced by total_paid. So the $total_unpaid has no results.
Is there any way I can make it work or any idea to make it more efficient and no repeating the base query?
Thanks
$querybefore fetching$total_paidand$total_unpaid(You'll get, for example,$queryand$query2). Then use$queryfor$total_paidand$query2for$total_unpaid. Here I presume that "cloning" is not "repeating".