Reputation: 557
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?
Upvotes: 3
Views: 2986
Reputation: 5
One more thing: in your applications's database config file config/database.php
Then mysql array, set strict => false
to disable MySQL's strict mode
Upvotes: 0
Reputation: 3935
Yes you have better version in eloquent
$day1 = Carbon::parse('last sunday')->startOfDay();
$day2 = Carbon::parse('next monday')->endOfDay();
$bills = Bills::whereBetween('created_at',$day1,$day2)->groupBy('created_at')->get();
$count = $bills->count();
Upvotes: 1