/** * * Registro en DB * */ function saveData() { static $result = array(); $codigo = rand(100000, 10000000); try { $ubicacion = new Ubicacion(); $ubicacion->codigo = $codigo; $ubicacion->usuario_id = Auth::user()->id; $ubicacion->categoria_id = Input::get('categoria'); $ubicacion->tipo_acceso_id = Input::get('tipo'); $ubicacion->x = Input::get('x'); $ubicacion->y = Input::get('y'); $ubicacion->nombre = Input::get('nombre'); $ubicacion->descripcion = Input::get('descripcion'); $ubicacion->etiquetas = Input::get('etiquetas'); $ubicacion->contacto = Input::get('contacto'); $ubicacion->estado = 1; $ubicacion->vigencia = Input::get('date') . " " . Input::get('time'); $ubicacion->usuario_creacion = Auth::user()->id; $ubicacion->save(); $result['flag'] = true; $result['msg'] = $ubicacion->id; } catch (Exception $err) { //return $err->getCode() . " / " . $err->getMessage(); if ($err->getCode() == 23000 and strpos($err->getMessage(), "Duplicate entry") !== false) { saveData(); } else { $result['flag'] = false; $result['msg'] = "Ocurrio un problema. (ID: {$codigo})"; } } return $result; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $data = Input::all(); $unidad = new Ubicacion(); $unidad->ubicacion = $data['ubicacion']; $unidad->save(); return Redirect::route('unidad.index'); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Ubicacion(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Ubicacion'])) { $model->attributes = $_POST['Ubicacion']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->idUbicacion)); } } $this->render('create', array('model' => $model)); }