how to get data from database as group by in eloquent
here is my code, but this is not working. so how to write this?
$list = Schedule::groupBy('date')->with('info')->paginate(20);
@mahbubrn Try this:
$list = Schedule::selectRaw('date, count(*) as total')
->groupBy('date')
->with('info')
->paginate(20);
@tisuchi its return me only total count number. not every row data.
Try this.
$subquery = Schedule::selectRaw('DISTINCT date')
->orderBy('date', 'desc')
->limit(100);
$list = Schedule::whereIn('date', $subquery)
->with('info')
->orderBy('date', 'desc')
->paginate(20);
Or
Show me your error. What is happening?
Or
use pluck('date')
Or
$users = User::orderBy('created_at')->get()->groupBy(function($data) {
return $data->timezone;
});
Please or to participate in this conversation.