Skip to content

Instantly share code, notes, and snippets.

@BastinRobin
Created January 13, 2019 08:02
Show Gist options
  • Select an option

  • Save BastinRobin/6110fe04d8caad4b76823e0b218420c8 to your computer and use it in GitHub Desktop.

Select an option

Save BastinRobin/6110fe04d8caad4b76823e0b218420c8 to your computer and use it in GitHub Desktop.
Grouping In Laravel
<?php
// for hours
UniqueView::get()->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('h');
});
// for minutes
UniqueView::get()->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('i');
});
// for seconds
UniqueView::get()->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('d');
});
// for Day
UniqueView::get()->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('s');
});
//for Month
UniqueView::get()->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('m');
});
// for year
UniqueView::get()->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('y');
});
// for year and month
UniqueView::get()->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('y-m');
});
// Last!
UniqueView::get()->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('y-m-d');
});
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment