Ejemplo n.º 1
0
 /**
  *
  * Proses Simpan Locations
  *
  * @throws \Exception
  * @return mixed
  */
 public function store()
 {
     if (!$this->hasAccess()) {
         return Response::json(array('success' => false, 'reason' => 'Action Need Login First', 'results' => null))->setCallback();
     }
     //        return Input::all();
     if (!Input::has('type')) {
         throw new \Exception('No Type Parameter');
     }
     $type = Input::get('type');
     $level = $this->convertTypeToLevel($type);
     //        $level = Input::get('level');
     /**
      * Control Control Name
      */
     $name = Input::get('name');
     if ($level == 1) {
         /*Nama Negara Tidak Boleh Sama */
         $exist = $this->locations->whereName($name)->count();
         if ($exist > 0) {
             return Response::json(array('success' => true, 'error' => true, 'reason' => 'Nama Negara harus Unique, sepertinya Negara Sudah ada'), 500);
         }
         $parentId = 0;
     } else {
         $parentId = Input::get('parent_id');
     }
     /*Proses Saving*/
     $uid = \Auth::user()->id;
     $newRecord = ['name' => $name, 'level' => $level, 'info' => Input::get('info'), 'uuid' => uniqid('New_'), 'parent_id' => $parentId, 'parent_type' => '\\Emayk\\Ics\\Repo\\Locations\\Locations', 'createby_id' => $uid, 'lastupdateby_id' => $uid, 'created_at' => Carbon::create(), 'updated_at' => Carbon::create()];
     $saved = $this->locations->create($newRecord);
     return Response::json(array('success' => $saved, 'error' => !$saved, 'results' => $saved->toArray(), 'reason' => $saved ? 'Saved' : 'Error Saved'))->setCallback();
 }