fix for not validating data after page refresh

This commit is contained in:
s416422 2020-01-20 12:05:33 +01:00
parent 8d488a87f8
commit e46e8ce3d2

View File

@ -141,14 +141,24 @@ class UserClassesController extends Controller {
$student_name = $request->input('student_name');
$student_surname = $request->input('student_surname');
$seat_number = $request->input('seat_number');
Attendance::create([
'classes_id' => $classes_id,
'student_id_number' => $student_id_number,
'student_name' => $student_name,
'student_surname' => $student_surname,
'seat_number' => $seat_number
]);
return view('map.summary_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'seat_number' => $seat_number, 'student_id_number' => $student_id_number, 'classes_id' => $classes_id, 'mode' => null, 'warning' => null]);
$classes = Classes::find($request->get('classes_id'));
$attendances = Attendance::where('classes_id', $classes->id)->get();
$student_ids = $attendances->pluck('student_id_number')->toArray();
if (in_array($student_id_number, $student_ids)) { // if student attendance record already exists
$student_seat_number = Attendance::where('student_id_number', $student_id_number)->first()->seat_number;
$warning = 'Ten numer indeksu został już wcześniej zapisany na te zajęcia.';
return view('map.summary_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'seat_number' => $student_seat_number, 'student_id_number' => $student_id_number, 'classes_id' => $classes->id, 'mode' => $classes->mode, 'warning' => $warning]);
} else {
Attendance::create([
'classes_id' => $classes_id,
'student_id_number' => $student_id_number,
'student_name' => $student_name,
'student_surname' => $student_surname,
'seat_number' => $seat_number
]);
return view('map.summary_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'seat_number' => $seat_number, 'student_id_number' => $student_id_number, 'classes_id' => $classes_id, 'mode' => null, 'warning' => null]);
}
}
public function preview_classes($classes_id, $orderBy = 'student_surname', $orderDirection = 'ASC') {