public function saveAs(Request $request) { // retrieve all records as collection $records = Dropout::select('report_date_id', 'institution_id', 'occupation_id', 'department', 'completed_level', 'regular_male', 'regular_female', 'extension_male', 'extension_female', 'short_term_male', 'short_term_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 Dropout::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('dropouts'); }
public function dropouts() { $result = Dropout::select(DB::raw('sum(regular_male) + sum(regular_female) as regular, sum(extension_male) + sum(extension_female) as extension, sum(short_term_male) + sum(short_term_female) as short_term, sum(regular_male) + sum(regular_female) + sum(extension_male) + sum(extension_female) + sum(short_term_male) + sum(short_term_female) as total'))->whereIn('report_date_id', ReportDate::select('id')->where('petsa', $this->petsa)->lists('id'))->whereIn('institution_id', Institution::select('id')->where('region_id', $this->region_id)->lists('id'))->get(); return $result; }