/** * Show the form for creating a new resource. * * @return Response */ public function create() { $rules = ['class' => 'required', 'section' => 'required', 'shift' => 'required', 'session' => 'required', 'regiNo' => 'required', 'date' => 'required', 'subject' => 'required']; $validator = \Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/attendance/create')->withInput(Input::all())->withErrors($validator); } else { $exits = Attendance::select('date')->where('class', Input::get('class'))->where('section', Input::get('section'))->where('shift', Input::get('shift'))->where('session', trim(Input::get('session')))->where('subject', Input::get('subject'))->where('date', $this->parseAppDate(Input::get('date')))->get(); if (count($exits) > 0) { $errorMessages = new Illuminate\Support\MessageBag(); $errorMessages->add('Duplicate', 'Attendance already saved!!'); return Redirect::to('/attendance/create')->withErrors($errorMessages); } else { $absentStudents = array(); $students = Input::get('regiNo'); $presents = Input::get('present'); $all = false; if ($presents == null) { $all = true; } else { $ids = array_keys($presents); } $stpresent = array(); foreach ($students as $student) { $st = array(); $st['regiNo'] = $student; if ($all) { $st['status'] = 'No'; } else { $st['status'] = $this->checkPresent($student, $ids); } if ($st['status'] == "No") { array_push($absentStudents, $student); } array_push($stpresent, $st); } foreach ($stpresent as $stp) { $attendance = new Attendance(); $attendance->class = Input::get('class'); $attendance->section = Input::get('section'); $attendance->shift = Input::get('shift'); $attendance->session = trim(Input::get('session')); $attendance->subject = Input::get('subject'); $attendance->regiNo = $stp['regiNo']; $attendance->status = $stp['status']; $attendance->date = $this->parseAppDate(Input::get('date')); $attendance->save(); } //get sms format //loop absent student and get father's no and send sms $isSendSMS = Input::get('isSendSMS'); if ($isSendSMS == null) { return Redirect::to('/attendance/create')->with("success", "Students attendance save Succesfully."); } else { if (count($absentStudents) > 0) { foreach ($absentStudents as $absst) { $student = DB::table('Student')->join('Class', 'Student.class', '=', 'Class.code')->select('Student.regiNo', 'Student.rollNo', 'Student.firstName', 'Student.middleName', 'Student.lastName', 'Student.fatherCellNo', 'Class.Name as class')->where('Student.regiNo', '=', $absst)->where('class', Input::get('class'))->first(); $msg = "Dear Parents your Child (Name-" . $student->firstName . " " . $student->middleName . " " . $student->lastName . ", Class- " . $student->class . " , Roll- " . $student->rollNo . " ) is Absent in School today."; // $fatherCellNo = Student::select('fatherCellNo','')->where('regiNo', $absst)->first(); $response = $this->sendSMS($student->fatherCellNo, "Supersoft", $msg); $smsLog = new SMSLog(); $smsLog->type = "Attendance"; $smsLog->sender = "Supersoft"; $smsLog->message = $msg; $smsLog->recipient = $student->fatherCellNo; $smsLog->regiNo = $absst; $smsLog->status = $response; $smsLog->save(); } return Redirect::to('/attendance/create')->with("success", "Students attendance saved and " . count($absentStudents) . " sms send to father numbers."); } else { return Redirect::to('/attendance/create')->with("success", "Students attendance save Succesfully."); } } } } }
public function deleteLog($id) { $sms = SMSLog::find($id); $sms->delete(); return Redirect::to('/smslog')->with("success", "SMS Log Deleted Succesfully."); }