Exemplo n.º 1
0
 /**
  * Creates a new Anak model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Anak();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 /**
  * Create new anak.
  *
  * @param Request $request
  * @return void
  */
 public function createAnak(Request $request)
 {
     $input = $request->input();
     $anak = new Anak();
     $anak->nama = $request->has('nama') ? $input['nama'] : '';
     $anak->id_type = $request->has('id_type') ? $input['id_type'] : 'kk';
     $anak->id_value = $request->has('id_value') ? $input['id_value'] : '';
     $anak->sekolah_terakhir = $request->has('sekolah_terakhir') ? $input['sekolah_terakhir'] : '';
     $anak->desa_id = $request->has('desa_id') ? $input['desa_id'] : '';
     $anak->kec_id = $request->has('kec_id') ? $input['kec_id'] : '';
     $anak->kab_id = $request->has('kab_id') ? $input['kab_id'] : '';
     $anak->prov_id = $request->has('prov_id') ? $input['prov_id'] : '';
     $anak->alamat = $request->has('alamat') ? $input['alamat'] : '';
     $anak->cp = $request->has('cp') ? $input['cp'] : '';
     $anak->status = 0;
     $anak->alasan = $request->has('alasan') ? $input['alasan'] : '';
     $anak->tanggal_lahir = $request->has('tanggal_lahir') ? $input['tanggal_lahir'] : '';
     $anak->gambar = "";
     // Upload handler
     if ($request->hasFile('gambar')) {
         $gambar = $request->file('gambar');
         $destination = base_path('public/uploads/anak/');
         $fileName = date('dmyhis') . $gambar->getClientOriginalName();
         $gambar->move($destination, $fileName);
         $anak->gambar = url('uploads/anak/' . $fileName);
     }
     if ($anak->save()) {
         return $anak;
     }
     return ['error' => true];
 }