mahbubrn's avatar

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);
0 likes
3 replies
tisuchi's avatar

@mahbubrn Try this:

$list = Schedule::selectRaw('date, count(*) as total')
                ->groupBy('date')
                ->with('info')
                ->paginate(20);
shaungbhone's avatar

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.