Ejemplo n.º 1
0
 public function update($id)
 {
     try {
         $registro = Categorias::find($id);
         if ($registro) {
             DB::beginTransaction();
             $registro->descripcion = Input::get('descripcion', $registro->descripcion);
             if ($registro->save()) {
                 DB::commit();
                 $respuesta['registros'] = $registro->toArray();
                 $respuesta['mensaje'] = 'Registro actualizado exitosamente';
                 $respuesta['resultado'] = true;
                 return $respuesta;
             } else {
                 DB::rollback();
                 $respuesta['registros'] = array();
                 $respuesta['mensaje'] = 'Error al actualizar registro';
                 $respuesta['resultado'] = false;
                 return $respuesta;
             }
         } else {
             $respuesta['registros'] = array();
             $respuesta['mensaje'] = 'El registro no existe';
             $respuesta['resultado'] = false;
             return $respuesta;
         }
     } catch (\Exception $e) {
         $respuesta['registros'] = array();
         $respuesta['mensaje'] = 'Error general: ' . $e;
         $respuesta['resultado'] = false;
         return $respuesta;
     }
 }
 public function update(CategoriasRequest $request, $id)
 {
     $categorias = Categorias::find($id)->update($request->all());
     return redirect()->route('categorias');
 }