public function updateAttendance(Request $request) { $course_id = $request->get('course_id'); $session_name = $request->get('session'); $day = $request->get('date'); $trainee_ids = Info::whereCourse_id($course_id)->lists('trainee_id'); foreach ($trainee_ids as $trainee_id) { $attendance = Attendance::wheretrainee_id($trainee_id)->whereCourse_id($course_id)->whereSession_name($session_name)->where('day', '=', Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $day . ' 00:00:00'))->firstorFail(); $attendance->trainee_attendance = $request->get('ta__' . $trainee_id); $attendance->update(); } $presents = Attendance::whereCourse_id($course_id)->whereSession_name($session_name)->where('day', '=', Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $day . ' 00:00:00'))->where("trainee_attendance", "P")->select('trainee_id')->get(); $present_att = array(); $i = 0; foreach ($presents as $present) { $present = Info::whereTrainee_id($present->trainee_id)->select('name')->firstorFail(); $present_att[$i++] = $present->name; } $absents = Attendance::whereCourse_id($course_id)->whereSession_name($session_name)->where('day', '=', Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $day . ' 00:00:00'))->where("trainee_attendance", "A")->select('trainee_id')->get(); $absent_att = array(); $j = 0; foreach ($absents as $absent) { $absent = Info::whereTrainee_id($absent->trainee_id)->select('name')->firstorFail(); $absent_att[$j++] = $absent->name; } $course_name = $this->course_name_by_course_id($course_id); $session = $request->get('session'); $date = $request->get('date'); return view('attendances.attendance_show', compact('present_att', 'absent_att'))->with('date', $date)->with('session', $session)->with('course_name', $course_name)->with('course_id', $course_id); }