public function saveAs(Request $request) { // retrieve all records as collection $records = Trainer::select('report_date_id', 'institution_id', 'occupation_id', 'level', 'full_time_male', 'full_time_female', 'part_time_male', 'part_time_female', 'ethiopian_male', 'ethiopian_female', 'non_ethiopian_male', 'non_ethiopian_female', 'core_male', 'core_female', 'took_tm_male', 'took_tm_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 Trainer::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('trainers'); }