I've asked this question before and it didn't get resolved, but I'm pretty sure I asked the question terribly. Here's my second attempt.
I have a collection and I need to output that collection grouped by a given timeframe (by week initially then as the site gets busier by day).
Here is the code I'm using to get the collection:
$latest = Site::query()
->with('upvotes')
->where([
['is_approved', '=', 2],
['is_featured', '=', 1],
])->orderBy('created_at', 'DESC')
->get();
I have tried various different ways of doing a "group by" but I don't think that's the solution.
What I'm trying to achieve is to run an @foreach in the blade and have the results output like this
Today
- Item 1
- Item 2
- Item 3
Yesterday
- Item 1
- Item 2
2 days ago
Item 1
Item 2
Item 3
Etc Etc...
It's proving fairly challenging.
it seems to me like what I need to achieve is something along the lines of
@foreach($dates as $date)
{{$date->diffForHumans()}}
@foreach($date->items as $item)
$item->name
$item->description
@endforeach
@endforeach
But I don't know, or can't figure out how to get there.
All help appreciated.