/** * Show the form for creating a new resource. * * @return Response */ public function create() { $rules = ['class' => 'required', 'section' => 'required', 'shift' => 'required', 'session' => 'required', 'regiNo' => 'required', 'exam' => 'required', 'subject' => 'required', 'written' => 'required', 'mcq' => 'required', 'practical' => 'required', 'ca' => 'required']; $validator = \Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/mark/create/')->withErrors($validator); } else { $gparules = GPA::select('gpa', 'grade', 'markfrom')->get(); // $totalMark = Input $len = count(Input::get('regiNo')); $regiNos = Input::get('regiNo'); $writtens = Input::get('written'); $mcqs = Input::get('mcq'); $practicals = Input::get('practical'); $cas = Input::get('ca'); $isabsent = Input::get('absent'); $counter = 0; for ($i = 0; $i < $len; $i++) { $isAddbefore = Marks::where('regiNo', '=', $regiNos[$i])->where('exam', '=', Input::get('exam'))->where('subject', '=', Input::get('subject'))->first(); if ($isAddbefore) { } else { $marks = new Marks(); $marks->class = Input::get('class'); $marks->section = Input::get('section'); $marks->shift = Input::get('shift'); $marks->session = trim(Input::get('session')); $marks->regiNo = $regiNos[$i]; $marks->exam = Input::get('exam'); $marks->subject = Input::get('subject'); $marks->written = $writtens[$i]; $marks->mcq = $mcqs[$i]; $marks->practical = $practicals[$i]; $marks->ca = $cas[$i]; $totalmark = $writtens[$i] + $mcqs[$i] + $practicals[$i] + $cas[$i]; $marks->total = $totalmark; foreach ($gparules as $gpa) { if ($totalmark >= $gpa->markfrom) { $marks->grade = $gpa->gpa; $marks->point = $gpa->grade; break; } } if ($isabsent[$i] !== "") { $marks->Absent = $isabsent[$i]; } $marks->save(); $counter++; } } if ($counter == $len) { return Redirect::to('/mark/create')->with("success", $counter . "'s student mark save Succesfully."); } else { $already = $len - $counter; return Redirect::to('/mark/create')->with("success", $counter . " students mark save Succesfully and " . $already . " Students marks already saved.</strong>"); } } }