I currently have this code using Eloquent:
CustomerSource::leftJoin("booking", "booking.customer_source_id", "=", "customer_source.id")
->selectRaw("customer_source.text, count(booking.id) as count")
->groupBy("text")
->where([
["booking_date", ">=", $from],
["booking_date", "<=", $to],
])->get()
with $to and $from being dates.
I need the query so that it counts the number of bookings made in a date range for each customer source.
When I remove the where condition, it lists all Customer sources, and the counts of bookings as it should (some can be 0), but when I include the where condition, it treats the query as if the join is an inner join and any customer sources that do not have any related bookings for the date period are not in the result set.
Please could you help me in figuring out the issue?