Beispiel #1
0
 public function save($id = null)
 {
     if ($id) {
         $kota = Kota::find($id);
     } else {
         $kota = new Kota();
     }
     $rule = ['nama' => 'required', 'provinsi_id' => 'required'];
     $this->validate($this->request, $rule);
     $input = $this->request->only('nama', 'provinsi_id');
     $kota->nama = $input['nama'];
     $kota->provinsi_id = $input['provinsi_id'];
     $kota->save();
     return redirect('kota');
 }
Beispiel #2
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 = Kota::find($id);
         $response['fields'] = $d->toArray();
         $response['output'] = view($this->viewForm, $response)->render();
     } elseif ($validation->passes()) {
         // Pas validasi berhasil
         $response['status'] = true;
         Kota::addOrModify($response['data'], $id);
     } else {
         // Pas validasi gagal
         $response['fields'] = $response['data'];
         $response['output'] = view($this->viewForm, $response)->render();
     }
     return $response;
 }