I have the following
->select(DB::raw('source as Source, customer as Customers, COUNT(*) as count'))
->groupBy('source', 'customer')
->get();
I get the follwing results
Illuminate\Support\Collection {#460 ▼
#items: array:4 [▼
0 => {#466 ▼
+"Source": "Facebook"
+"Customer": "Yes"
+"count": 227
}
1 => {#463 ▼
+"Source": "PinInterest"
+"Customer": "Yes"
+"count": 370
}
2 => {#465 ▼
+"Source": "PinInterest"
+"Customer": "No"
+"count": 133
}
3 => {#467 ▼
+"Source": "Whatsapp"
+"Customer": "No"
+"count": 254
}
]
}
Now Source can be 1 - 10 different channels depending on the customer. Now Customer Be Yes or No.
How do I add modify collection to add Source Facebook, Customer No and Count 0, and Source WhatsApp, Customer Yes and Count 0
Source : Facebook Customer : Yes Count : 227
Source : Facebook Customer : No Count : 0
Source : Whatsapp Customer : No count : 254
Source : Whatsapp Customer : Yes count : 0
Using laravel's collection helpers you can add missing data in your original collection as
Transformation
Output