/** * { delete } * * @param * 1. id * 2. org_id * 3. input name * 4. input address * 5. input email * 6. input phone * * @return * 1. response * * steps * 1. validate * 2. get data * 3. post to API * 4. return response */ public function delete($org_id = null, $employee = null, $id = null) { //1. validate if (is_null($org_id)) { App::abort(403, 'Id Organisasi tidak ada'); } //2. get data $APIEmployee = new APIEmployee(); $data = $APIEmployee->getShow($org_id, $employee)['data']; foreach ($data['works'] as $key => $value) { if ($value['id'] == $id) { unset($data['works'][$key]); } } if (empty($data['works'])) { $data['works'] = null; } //3. post to API $APIEmployee = new APIEmployee(); $result = $APIEmployee->postData($org_id, $data); //4. return response if ($result['status'] != 'success') { $this->errors = $result['message']; } $this->page_attributes->msg = "Data Pekerjaan Telah Dihapus"; return $this->generateRedirectRoute('org.show', ['id' => $org_id]); }
/** * { store } * * @param * 1. id * 2. org_id * 3. input name * 4. input address * 5. input email * 6. input phone * * @return * 1. response * * steps * 1. validate * 2. get input * 3. get data * 4. post to API * 5. return response */ public function store($org_id = null, $id = null) { //1. validate if (is_null($org_id)) { App::abort(403, 'Id Organisasi tidak ada'); } //2. get input $input = Input::all(); //3. get data if (!is_null($id)) { $APIEmployee = new APIEmployee(); $data = $APIEmployee->getShow($org_id, $id)['data']; $data = $input; $data['id'] = $id; } else { $data = $input; $data['id'] = ''; $data['works'][0]['id'] = ''; $data['maritalstatuses'][0]['id'] = ''; $data['maritalstatuses'][0]['status'] = $input['current_marital_status']; $data['maritalstatuses'][0]['ondate'] = Carbon::now()->format('Y-m-d H:i:s'); if (empty($input['works'][0]['end'])) { $data['works'][0]['end'] = '0000-00-00 00:00:00'; } } //3. post to API $APIEmployee = new APIEmployee(); $result = $APIEmployee->postData($org_id, $data); //4. return response if ($result['status'] != 'success') { $this->errors = $result['message']; } if (!empty($id)) { $this->page_attributes->msg = "Data Karyawan Telah Diedit"; } else { $this->page_attributes->msg = "Data Karyawan Telah Ditambahkan"; } return $this->generateRedirectRoute('org.show', ['id' => $org_id]); }