1 year ago

Return Year Count Even When Count is 0

Posted 1 year ago by mprythero

I'm trying to work on a chart with a few datasets, however for the purposes of asking this question, I will only include one.

At the moment if I have the following in my controller:

$maintenancesForklifts = DB::table("equipment_attachments")
                        ->join('equipment as equip', '', '=', 'equipment_attachments.unitID')
                        ->select(DB::raw('year(date) as year'), DB::raw("COUNT(*) as count"))

I will get this returned:


As you can see there are a few years missing if I went from say 2000 to the present day. Do you know how I could return the results so that they would come back with the years that have a zero count?


Please sign in or create an account to participate in this conversation.