Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 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');
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 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');
     }
 }