I want to show photos grouped by date. It works, but only with two queries and without pagination. Is there a way to do it with only one query, with laravels paginate() ? I need the last 5 days (only those that have pictures), and then always 5 days per page.
The problem is, that i want to paginate the days, not the pictures.
$days = Pic::select(DB::raw('DATE(created_at) as datum'))
->distinct()
->orderBy('datum','desc')
->take(5)
->get();
$daysarray = array();
foreach($days as $day)
{
$pics = Pic::where(DB::raw('DATE(created_at)'),'=',$day->datum)
->orderBy('id','desc')
->get();
$daysarray[$day->datum] = $pics;
}