title: laravel query builder with conditions
body: <p>I am implementing a query to draw a multiple line chart using chartjs. I have an array of dates </p>
  
  <pre><code>["2016-10-16","2016-10-17","2016-10-18","2016-10-19","2016-10-20","2016-10-21","2016-10-22","2016-10-23","2016-10-24","2016-10-25","2016-10-26","2016-10-27","2016-10-28","2016-10-29","2016-10-30","2016-10-31","2016-11-01","2016-11-02","2016-11-03","2016-11-04","2016-11-05","2016-11-06","2016-11-07","2016-11-08","2016-11-09","2016-11-10","2016-11-11","2016-11-12","2016-11-13","2016-11-14","2016-11-15","2016-11-16"]
  </code></pre>
  
  <p>This array has dates between "2016-11-16" and "2016-10-16".</p>
  
  <p>I have created a model <code>Tickets</code>, and I wrote a query to fetch tickets count grouped by <code>tickets.status</code>.</p>
  
  <pre><code>$join = $this-&gt;tickets();
  $tickets = $join
           -&gt;when($category, function($query) use ($category) {
               $ranges = $this-&gt;dateRange($category);
               return $query-&gt;whereBetween('tickets.created_at', $ranges);
           })
           -&gt;select(DB::raw('COUNT(tickets.id) as tickets'), 'ticket_status.name as name', 'tickets.created_at')
           -&gt;groupBy('ticket_status.name', 'tickets.created_at')
           -&gt;get();
  </code></pre>
  
  <p>Executing this query I got</p>
  
  <pre><code>[
      {
          "tickets":"1",
          "name":"Closed",
          "created_at":"2016-11-08 14:07:32"
      },
      {
          "tickets":"1",
          "name":"Open",
          "created_at":"2016-11-08 14:07:32"
      },
      {
          "tickets":"1",
          "name":"Open",
          "created_at":"2016-11-11 12:24:39"
      },
      {
          "tickets":"1",
          "name":"Open",
          "created_at":"2016-11-11 12:26:38"
      },
      {
          "tickets":"1",
          "name":"Open",
          "created_at":"2016-11-11 12:27:04"
      },
      {
          "tickets":"1",
          "name":"Open",
          "created_at":"2016-11-11 12:27:49"
      },
      {
          "tickets":"1",
          "name":"Open",
          "created_at":"2016-11-11 12:28:47"
      },
      {
          "tickets":"1",
          "name":"Resolved",
          "created_at":"2016-11-08 14:07:32"
      }
  ]
  </code></pre>
  
  <p>If <code>$label[0] != $tickets.created</code>, ticket and name will be null but should have date</p>
  
  <p>Please help me to get output like</p>
  
  <pre><code>[
      [
          'tickets'=&gt;0,
          'name'=&gt;null,//tickets don't have this date
          'created_at'=&gt;'2016-10-16'
      ],
      [
          'tickets'=&gt;0,
          'name'=&gt;null,//tickets don't have this date
          'created_at'=&gt;'2016-10-15'
      ],
      [
          'tickets'=&gt;1,
          'name'=&gt;'closed',//on this date 1 closed ticket
          'created_at'=&gt;'2016-10-14'
      ],
      [
          'tickets'=&gt;3,
          'name'=&gt;'open',//on this date 3 open ticket
          'created_at'=&gt;'2016-10-14'
      ],
      [
          'tickets'=&gt;2,
          'name'=&gt;'resolved',//on this date 2 resolved ticket
          'created_at'=&gt;'2016-10-14'// on 2016-10-14 has three different tickets
      ],
      ...........
  ]
  </code></pre>
  
  <p>Please help me to find a solution. Thanks in advance.</p>