app/Http/Controllers/ExamController.php
/*	insert new student with their sore data if they dont exist!!!
				*/
insert new student with their sore data if they dont exist
insert new student with their sore data if they dont exist
public function Information(Request $request)
	{
			$subject = $request->subject;
			$examid = $request->examid;
			$c = count($request->checked);
		   for ($x = 0; $x < $c; $x++){
								if(!DB::table('result')->where('studentid', $request->studentid[$x])
									->where ('examid', $examid)->first())
							{
								$result = new Result();
									$student = Student::where('id', $request->studentid[$x])->firstorfail();
									$result->username = $student->username;
									$result->regno = $student->regno;
									$result->yos = $student->yos;
									$result->acadamicyear = $student->academicyear;
									$result->examid = $examid;
									$result->classid = $request->classesid;
									$result->$subject = $request->score[$x];
									$result->studentid = $request->studentid[$x];
									$result -> save();
								return Redirect::to('/admin/exams')
								->with('message', 'info updated!!!');
							}else{
									$result = Result::where('studentid', $request->studentid[$x])
											->where ('examid', $examid)->first();
									$student = Student::where('id', $request->studentid[$x])->first();
									$result->username = $student->username;
									$result->regno = $student->regno;
									$result->yos = $student->yos;
									$result->acadamicyear = $student->academicyear;
									$result->examid = $examid;
									$result->classid = $request->classesid;
									$result->$subject = $request->score[$x];
									$result->studentid = $request->studentid[$x];
									$result -> save();
								return Redirect::to('/admin/exams')
								->with('message', 'info updated accordingly!!!');	
								}
		 		  }
								return Redirect::to('/admin/exams')
									->with('message', 'info updated.');
	}
public function Information ( Request $ request ) { $ subject = $ request -> subject ; $ examid = $ request -> examid ; $ c = count ( $ request -> checked ) ; for ( $ x = 0 ; $ x < $ c ; $ x ++ ) { if ( ! DB :: table ( 'result' ) -> where ( 'studentid' , $ request -> studentid [ $ x ] ) -> where ( 'examid' , $ examid ) -> first ( ) ) { $ result = new Result ( ) ; $ student = Student :: where ( 'id' , $ request -> studentid [ $ x ] ) -> firstorfail ( ) ; $ result -> username = $ student -> username ; $ result -> regno = $ student -> regno ; $ result -> yos = $ student -> yos ; $ result -> acadamicyear = $ student -> academicyear ; $ result -> examid = $ examid ; $ result -> classid = $ request -> classesid ; $ result -> $ subject = $ request -> score [ $ x ] ; $ result -> studentid = $ request -> studentid [ $ x ] ; $ result -> save ( ) ; return Redirect :: to ( '/admin/exams' ) -> with ( 'message' , 'info updated!!!' ) ; } else { $ result = Result :: where ( 'studentid' , $ request -> studentid [ $ x ] ) -> where ( 'examid' , $ examid ) -> first ( ) ; $ student = Student :: where ( 'id' , $ request -> studentid [ $ x ] ) -> first ( ) ; $ result -> username = $ student -> username ; $ result -> regno = $ student -> regno ; $ result -> yos = $ student -> yos ; $ result -> acadamicyear = $ student -> academicyear ; $ result -> examid = $ examid ; $ result -> classid = $ request -> classesid ; $ result -> $ subject = $ request -> score [ $ x ] ; $ result -> studentid = $ request -> studentid [ $ x ] ; $ result -> save ( ) ; return Redirect :: to ( '/admin/exams' ) -> with ( 'message' , 'info updated accordingly!!!' ) ; } } return Redirect :: to ( '/admin/exams' ) -> with ( 'message' , 'info updated.' ) ; }
insert new student with their sore data if they dont exist!!
insert new student with their sore data if they dont exist!!
///use yos and accademic year to be precise /*else{
									
								return Redirect::to('/admin/exams')
								->with('message', 'info Already exist in the database!!!');
								}*/