Created
January 13, 2019 08:02
-
-
Save BastinRobin/6110fe04d8caad4b76823e0b218420c8 to your computer and use it in GitHub Desktop.
Grouping In Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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