/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { // $newProduct = new Productos($request->all()); $newProduct->save(); Flash::success("El producto " . $newProduct->nombre . " ha sido creado correctamente"); return redirect()->route('admin.products.index'); }
public function store() { try { if (Input::get('sku') && Input::get('nombre') && Input::get('descripcion') && Input::get('precio')) { DB::beginTransaction(); $registro = new Productos(); $registro->tipo = Input::has('tipo') ? 1 : 0; $registro->sku = Input::get('sku'); $registro->nombre = Input::get('nombre'); $registro->descripcion = Input::get('descripcion'); $registro->precio = Input::get('precio'); $registro->foto = '-'; $registro->idunidad = Input::get('idunidad'); $registro->idcategoria = Input::get('idcategoria'); $registro->idempresa = Session::get('idempresa'); if ($registro->save()) { DB::commit(); $respuesta['registros'] = $registro->toArray(); $respuesta['mensaje'] = 'Registro creado exitosamente'; $respuesta['resultado'] = true; return $respuesta; } else { DB::rollback(); $respuesta['registros'] = array(); $respuesta['mensaje'] = 'Error al crear el registro'; $respuesta['resultado'] = false; return $respuesta; } } else { $respuesta['registros'] = array(); $respuesta['mensaje'] = 'Todos los campos son requeridos'; $respuesta['resultado'] = false; return $respuesta; } } catch (\Exception $e) { $respuesta['registros'] = array(); $respuesta['mensaje'] = 'Error general: ' . $e; $respuesta['resultado'] = false; return $respuesta; } }