Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Laravel: Групована по роках і місяцях колекція для виводу новин
$news = News::published()->active()->get()->groupBy(function ($date) {
return Carbon::parse($date->published_at)->formatLocalized('%Y');
});
$grouped = $news->map(function ($date) {
return ($date->groupBy(function ($item) {
return Carbon::parse($item->published_at)->formatLocalized('%B');
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment