Q: LARAVEL row cloning getting select SQL error Hi I've been stuck here for days now,
I am trying clone a row from my DB using the replicate method. But I am getting the error
Here is my code:
 foreach($e_inserts as $e_data){
$enrollment = \App\Enrollment::find($e_data['enrollment_id']); //CLONE ENROLLMENTS
                                $new_enrollment = $enrollment->replicate();
                                $new_enrollment->term_id = $input['term_to'];
                                $new_enrollment->enrollment_status = 'waiving';
                                $new_enrollment->save();
}

I am getting a select error for an insert
1SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row (SQL: insert into `enrollments` (`user_id`, `participation_id`, `term_id`, `email`, `ssn`, `student_id`, `effective_date`, `termination_date`, `last_name`, `first_name`, `middle_initial`, `dob`, `gender_code`, `identify_as`, `academic_level`, `enrollee_category`, `address`, `address2`, `city`, `state`, `zip`, `zip_reserve`, `phone`, `alt_phone`, `notification_phone`, `emergency_contact_first_name`, `emergency_contact_last_name`, `emergency_contact_relationship`, `emergency_contact_phone`, `emergency_contact_email`, `beneficiary_contact_first_name`, `beneficiary_contact_last_name`, `beneficiary_contact_relationship`, `beneficiary_contact_phone`, `beneficiary_contact_email`, `academic_status`, `opt_status`, `enrollment_status`, `dependents`, `spouse`, `agree`, `no_us_address`, `country_of_study`, `home_country`, `ead_start_date`, `ead_end_date`, `action_taken`, `completed`, `status_updated_at`, `deleted_at`, `carrier_sent`, `carrier_member_id`, `custom_history`, `locked`, `updated_at`, `created_at`) values (59536, 728, 2777, smartfox.manuel+carryover_waived_2@gmail.com, , test_waived_2, ?, ?, Email, Match, , 2000-01-01, M, , UNDG, DOM, 6162 Rotary Way, , Joshua Tree, CO, 92252, , test_waived_2, , none, test_waived_2, test_waived_2, test_waived_2, test_waived_2, , ?, ?, ?, ?, ?, FT, out, waiving, 0, 0, 1, 1, ?, ?, ?, ?, 0, 2021-07-25 11:57:35, 2021-07-27 03:20:09, ?, ?, ?, ?, 0, 2021-07-27 06:30:30, 2021-07-27 06:30:30))" 


A: Try this instead
$new_enrollment = $enrollment->replicate()->fill([
   'term_id' = $input['term_to'];
   'enrollment_status' = 'waiving';
]);

$new_enrollment->save();

