'for loop is only looping once in Laravel 8

I have a loop that is only looping once.

Below is the code, I do not know why it is doing such.

I want the code to loop according to the number of students below is the code.

What could be the reason the script is only looping once?

$combined = [];

            // dd($students);


            foreach ($students as $key => $val) {

                
                $combined[] = ['student_id'=>$val, 'result'=>$result[$key], 'present_class'=>$present_class[$key]];

                $student=$combined[$key]['student_id'];
                $final_status=$combined[$key]['result'];
                $current_class=$combined[$key]['present_class'];

                $class_map_exists=ClassSequence::where('origin', $current_class)->exists();
                $class_map_doesnt_exist=ClassSequence::where('origin', $current_class)->doesntexist();

                if ($class_map_exists) {
                    //if class-map exists for that class
                    //get the next class
                    $next_class=ClassSequence::where('origin', $current_class)->first();
                    $destination=$next_class->destination;
                       
                    if ($final_status=='Proceed' or $final_status=='Promoted') {
                       

                        $create_new_entry=StudentClass::updateOrCreate(
                            ['student_id' => $student, 'grade_id' => $destination, 'academic_session' => $to_session, 'active'=>1],
                            ['student_id' => $student, 'grade_id' => $destination, 'academic_session' => $to_session, 'active'=>1]
                        );
                    }

                    if ($final_status=='Repeat') {
                        $create_new_entry=StudentClass::updateOrCreate(
                            ['student_id' => $student, 'grade_id' => $current_class, 'academic_session' => $to_session, 'active'=>1],
                            ['student_id' => $student, 'grade_id' => $current_class, 'academic_session' => $to_session, 'active'=>1]
                        );
                    }

                    if ($final_status=='Try Another School') {
                      
                        User::find($student)->update(['active']);
                    }
                        
                    flash()->overlay('<i class="fas fa-check-circle text-success "></i>'.' Congratulations. You have successfully migrated students to the next class', 'Migration Process Notice');
                    return Redirect::back();
                } else {
                    // if($class_map_doesnt_exist){
                    //else if it does not exist
              
                    flash()->overlay('<i class="fas fa-check-circle text-warning "></i>'.' Sorry. Class Mapping does not exist. Please map classes first, to do so, please click '.'<a href=/class-sequencing> here</a>', 'Migration Process Notice');
                    return Redirect::back();
                }
            }
        }



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source