0

I have a little code to group by day:

$data->get()->groupBy(function($data) {
    return Carbon::parse($data->start)->format('Y-m-d');
});

I need this to display on chartjs as dataset and labels.

It works but, if there is no data for one date, it get skipped, case:

2019-02-01 - 5
2019-02-03 - 5
2019-02-04 - 5

But I would need something like this:

2019-02-01 - 5
2019-02-02 - 0
2019-02-03 - 5
2019-02-04 - 5

So is there a way to group by each day from between two dates?

Learner
  • 723
  • 3
  • 13
  • 36
  • 1
    Only if you join to a calendar table with all the dates defined – RiggsFolly Feb 26 '19 at 22:44
  • @RiggsFolly is it a overkill if I get array of days like this: https://stackoverflow.com/a/50854594/10230696 and call custom query for each? I mean it is if range is 3 months with 90 different dates.... Or get array of dates like I already do and check if array of days is in array of dates? if not to add it and asign 0? – Learner Feb 26 '19 at 22:50
  • Possible duplicate of [Laravel - fill up missing dates and counts from database](https://stackoverflow.com/questions/37389281/laravel-fill-up-missing-dates-and-counts-from-database) – Ahmed Nour Jamal El-Din Feb 27 '19 at 04:35

0 Answers0