public static function update($in) { $desa = Desa::find($in['id']); $desa = DesaDAO::exchangeArray($desa, $in); $kec = Kecamatan::find($in['kecamatan']); if (!is_null($desa->first())) { $desa->kecamatan()->associate($kec); } $desa->update(); return $desa; }
public function save($id = null) { if ($id) { $kecamatan = Kecamatan::find($id); } else { $kecamatan = new Kecamatan(); } $rule = ['nama' => 'required', 'kota_id' => 'required']; $this->validate($this->request, $rule); $input = $this->request->only('nama', 'kota_id'); $kecamatan->nama = $input['nama']; $kecamatan->kota_id = $input['kota_id']; $kecamatan->save(); return redirect('kecamatan'); }
public function responseEdit($id) { $response = parent::responseEdit($id); $validation = $response['validation']; unset($response['validation']); if ($response['initial'] == true) { // Pas form baru kebuka $response['errors'] = []; $d = Kecamatan::find($id); $response['fields'] = $d->toArray(); $response['output'] = view($this->viewForm, $response)->render(); } elseif ($validation->passes()) { // Pas validasi berhasil $response['status'] = true; Kecamatan::addOrModify($response['data'], $id); } else { // Pas validasi gagal $response['fields'] = $response['data']; $response['output'] = view($this->viewForm, $response)->render(); } return $response; }
public function delete($id) { $kec = Kecamatan::find($id); $nama = $kec->nama; if (!is_null($kec->first())) { $kec->delete(); Session::flash('message', "Kecamatan {$nama} has been deleted!"); return Redirect::to('/dash/setting/kecamatan'); } else { Session::flash('message', "Error, Kecamatan with {$id} not found!"); return Redirect::to('/dash/setting/kecamatan'); } }