public function saveAs(Request $request) { // retrieve all records as collection $records = IndustryExtension2::select('report_date_id', 'institution_id', 'subsector_id', 'starter_enterprise', 'starter_mse_operator_male', 'starter_mse_operator_female', 'starter_mse_operator_supported_male', 'starter_mse_operator_supported_female', 'advance_enterprise', 'advance_mse_operator_male', 'advance_mse_operator_female', 'advance_mse_operator_supported_male', 'advance_mse_operator_supported_female', 'competent_enterprise', 'competent_mse_operator_male', 'competent_mse_operator_female', 'competent_mse_operator_supported_male', 'competent_mse_operator_supported_female', 'remarks')->where('report_date_id', $request->report_date_id_source)->get(); if (count($records) > 0) { // update report date id to target report date id foreach ($records as $rec) { $rec->report_date_id = $request->report_date_id_target; } // insert into the table IndustryExtension2::insert($records->toArray()); // send a flash message $request->session()->flash('alert-success', 'Save as operation was successful!'); } else { // send a flash message $request->session()->flash('alert-danger', 'Save as operation failed! No records found from source.'); } return redirect('industry-extension-2'); }