i am trying to check array of data, so user cannot add same data at once. what my code look like:
for ($count = 0; $count < count($class_id); $count++) {
$data = array(
'class_id' => $class_id[$count],
'section_id' => $section_id[$count],
'teacher_id' => $teacher_id[$count],
'days' => $days[$count],
'Start_Time' => $start_time[$count],
);
$insert_data[] = $data;
}
for($count=1; $count<count($insert_data);$count++){
if($insert_data[$count]['class_id']&&$insert_data[$count]['section_id']&&$insert_data[$count]['teacher_id']
&&$insert_data[$count]['days']&&$insert_data[$count]['Start_Time']){
return response()->json([
'error' => 'Same data cannot be insert'
]);
}
}
Timetable::insert($insert_data);
return response()->json([
'success' => 'Data Added successfully.',
'redirect' => url('/manage/timetable'),
]);
}
return redirect('/manage/timetable')->with('message','Data Added Successfully!');
}
data inserted correctly, everything working fine, what i want to do is to check if user insert same data 2 time or not? i uses for loop for that. what i am doing wrong? it give me "Cannot add same data" even if i change i field still gives me this error. new to laravel.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire