I am trying to make an archive with Laravel where I can store written articles. I want this to have a structure like:
- Today
- Article 1
- This week
- Article 2
- article 3
- This month
- Article 4
- This year
- Article 4
And when there are no articles in, for example "Today", the title "Today" is not shown. Same for any other category.
I managed to make an archive where I could store articles within a specific format, like per year:
$archives = Article::all()->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('Y');
});
but is it possible to achive the list I gave above with some changes to the code I have now or with some other code?