public function store_attendance(AttendanceFormRequest $request)
 {
     $course_id = $request->get('course_id');
     $session_name = $request->get('session');
     $day = $request->get('date');
     $check = Attendance::whereCourse_id($course_id)->whereSession_name($session_name)->where('day', '=', Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $day . ' 00:00:00'))->count('id');
     if ($check) {
         $trainees = DB::table('traineecourses')->join('users', 'traineecourses.trainee_id', '=', 'users.id')->where('traineecourses.course_id', $course_id)->select('name', 'users.id')->get();
         $course_name = $this->course_name_by_course_id($course_id);
         return view('attendances.attendance_create')->with('trainee_list', $trainees)->with('date', $request->get('date'))->with('session', $request->get('session'))->with('course_name', $course_name)->with('course_id', $course_id)->with('warning', "This attendance is already entered.");
     } else {
         $trainee_ids = TraineeCourse::whereCourse_id($course_id)->lists('trainee_id');
         foreach ($trainee_ids as $trainee_id) {
             $attendance = new Attendance();
             $attendance->day = Carbon\Carbon::createFromFormat('Y-m-d', $day);
             $attendance->trainee_id = $trainee_id;
             $attendance->session_name = $session_name;
             $attendance->course_id = $course_id;
             $attendance->trainee_attendance = $request->get('ta__' . $trainee_id);
             $attendance->save();
         }
         $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 = User::whereId($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 = User::whereId($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);
     }
 }
 public function store_attendance(AttendanceFormRequest $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 = new Attendance();
         $attendance->day = Carbon\Carbon::createFromFormat('Y-m-d', $day);
         $attendance->trainee_id = $trainee_id;
         $attendance->session_name = $session_name;
         $attendance->course_id = $course_id;
         $attendance->trainee_attendance = $request->get('ta__' . $trainee_id);
         $attendance->save();
     }
     $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);
     $course_id = $request->get('course_id');
     $trainee_ids = Info::whereCourse_id($course_id)->lists('trainee_id');
     $day = $request->get('date');
     $trainee_ids = Info::whereCourse_id($course_id)->lists('trainee_id');
     $day = $request->get('date');
     $session_name = $request->get('session');
     foreach ($trainee_ids as $trainee_id) {
         $attendance = new Attendance();
         $attendance->day = $day;
         $attendance->trainee_id = $trainee_id;
         $attendance->session_name = $session_name;
         $attendance->course_id = $course_id;
         $attendance->trainee_attendance = $request->get('ta__' . $trainee_id);
         $attendance->save();
         $attendance->trainee_attendance = $request->get('ta__' . $trainee_id);
         $attendance->save();
         //new code
         $trainee_attendances = Attendance::whereCourse_id($course_id)->lists('trainee_attendance');
         return $trainee_attendances;
         $collection = collect($trainee_attendances);
         // return $collection->count();
     }
     //new code
     $trainee_attendances = Attendance::whereCourse_id($course_id)->lists('trainee_attendance');
     $present = Attendance::whereCourse_id($course_id)->where("trainee_attendance", "P")->count('trainee_attendance');
     //return $present;
     $absent = Attendance::whereCourse_id($course_id)->where("trainee_attendance", "A")->count('trainee_attendance');
     //return $absent;
     $course_name = $this->course_name_by_course_id($course_id);
     $session = $request->get('session');
     $date = $request->get('date');
     return view('attendances.attendance_show')->with('date', $date)->with('session', $session)->with('course_name', $course_name)->with('course_id', $course_id)->with('present', $present)->with('absent', $absent);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show_attendance_form_function(AttendanceFormRequest $request)
 {
     $course_id = $request->get('course_id');
     $date = $request->get('date');
     $session = $request->get('session');
     $trainee_list = Info::whereCourse_id($course_id)->get();
     $course_name = $this->course_name_by_course_id($course_id);
     return view('attendances.attendance_create')->with('trainee_list', $trainee_list)->with('date', $date)->with('session', $session)->with('course_name', $course_name)->with('course_id', $course_id);
     $present = Course::whereCourse_id($course_id)->where("trainee_attendance", "P")->count("trainee_attendance");
     return $present;
     $absent = Course::whereCourse_id($course_id)->where("trainee_attendance", "A")->count("trainee_attendance");
     /*$attendance = new Attendance(array(
             'day' => $request->get('date'),
             'session_name' => $request->get('session'),
     
             //'trainee_attendance' => $request->get('attendance'),
            
            
              ));
         $attendance->save();*/
 }