Latest

Monday, July 10, 2017

Laravel Eloquent grouping by days of the week

Asked by: Sai Krishna


I'm currently using this

 Bills::select( \DB::raw('DATE(`created_at`) as `date`'),\DB::raw('COUNT(*) as `count`'))->whereBetween('created_at', [Carbon\Carbon::parse('last sunday')->startOfDay(),Carbon\Carbon::parse('next monday')->endOfDay(), ]) ->groupBy('date')->get() ;

but is there better Eloquent query to search within the calendar week and group the daily count by days?



Source

No comments:

Post a Comment

Adbox