Created
April 3, 2017 16:18
-
-
Save febridev/8b79ca06ed5923cd8d5f09ee10d83fdf to your computer and use it in GitHub Desktop.
eloquent laravel group by year
This file contains 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
// Carbon | |
use Carbon\Carbon; | |
$visitorTraffic = PageView::select('id', 'title', 'created_at') | |
->get() | |
->groupBy(function($date) { | |
return Carbon::parse($date->created_at)->format('Y'); // grouping by years | |
//return Carbon::parse($date->created_at)->format('m'); // grouping by months | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@theinizio thank you