groupBy = $groupBy; } public function sheets(): array { $user_id = Auth::id(); $subjects = Subject::where('user_id', $user_id)->get(); $subjects_ids = $subjects->pluck('id')->toArray(); $classes = Classes::whereIn('subject_id', $subjects_ids)->orderBy('created_at','DESC')->get(); $classes_ids = $classes->pluck('id')->toArray(); $attendances = Attendance::whereIn('classes_id', $classes_ids)->get(); $attendances_grouped = $attendances->groupBy($this->groupBy); foreach ($attendances_grouped as $attendances_group_name => $attendances_list) { $sheets[] = new AttendanceGroupedExportSingleView($attendances_list, $this->groupBy, $attendances_group_name); } return $sheets; } }