Im using Chart.js to show the number of bookings for each month. This is my query. It is working fine. My problem is if there is no booking in a month then it doesnt show anything. No zero value. On the chart i get the value like
- January 23
- February 34
- April 23
- May 25
- July 42
March and June are shown on the chart..How can i get the value Zero for months where there is no booking..
$graph = DB::table('bookings')
->select(DB::raw('MONTHNAME(created_at) as month'), DB::raw("DATE_FORMAT(created_At,'%M %Y') as monthNum"), DB::raw('count(*) as totalbook'))
->groupBy('monthNum')
->orderBy('created_at', 'asc')
->get();
To get months,`
@foreach ($graph as $dat)
"{!! $dat->monthNum !!}",
@endforeach`
And to get booking numbers
@foreach ($graph as $dat)
{!! $dat->totalbook !!},
@endforeach