Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DDiimmkkaass/2ed2afc96b4ab96028ec6e3e49d3eade to your computer and use it in GitHub Desktop.
Save DDiimmkkaass/2ed2afc96b4ab96028ec6e3e49d3eade to your computer and use it in GitHub Desktop.
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