Right now i'm buliding export to csv function from db .
I was a long journey to complete it , a part of format or style in csv files is the to list the performance report by daily including the day without no sales at all . This is client request .
I have a lot of question to ask but now this the main priority .
I have query :
$period = DB::table('reports')->select('id','quantity','created_date')->whereBetween('created_date',$timerange)->where('branch_id',$br_id)->orderBy('created_date','asc')->get();
Result : (i'm using var_dump)
array (size=3)
0 =>
array (size=2)
'created_date' => string '2016-02-18 00:00:00' (length=19)
'quantity' => int 1
1 =>
array (size=2)
'created_date' => string '2016-02-20 00:00:00' (length=19)
'quantity' => int 1
2 =>
array (size=2)
'created_date' => string '2016-02-23 00:00:00' (length=19)
'quantity' => int 1
The question is how to turn the result into this even there is no record on that date .
Example :
array (size=3)
0 =>
array (size=2)
'created_date' => string '2016-02-18 17:21:04' (length=19)
'quantity' => int 1
1 =>
array (size=2)
'created_date' => string '2016-02-19 17:21:04' (length=19)
'quantity' => int 0
2 =>
array (size=2)
'created_date' => string '2016-02-20 00:00:00' (length=19)
'quantity' => int 1
3 =>
array (size=2)
'created_date' => string '2016-02-21 00:00:00' (length=19)
'quantity' => int 0
4 =>
array (size=2)
'created_date' => string '2016-02-22 00:00:00' (length=19)
'quantity' => int 0
5 =>
array (size=2)
'created_date' => string '2016-02-23 00:00:00' (length=19)
'quantity' => int 1
Thank you