/** * * @param int $id * @return Response */ public function update(RegisterPublicationRequest $request, $id) { try { $this->haveAdsForUser($id); $dataAds = $request->all(); $objAds = PuAds::find($id); $objAds->update($dataAds); if (isset($dataAds['picture'])) { $objPicture = PuPicture::wherePuAdId($id); $objPicture->delete(); $file = base64_decode($dataAds['picture']); $dataPicture['name_picture'] = date('YmdHis') . rand(1, 1000) . ".jpg"; $pathrelative = "/dinamic/publication/" . $dataPicture['name_picture']; $path = App::publicPath() . $pathrelative; file_put_contents($path, $file); $dataPicture['url'] = $pathrelative; $dataPicture['pu_ad_id'] = $objAds->id; PuPicture::create($dataPicture); } $this->_responseWS->setDataResponse(Response::HTTP_CREATED, ['id' => $objAds->id], [], 'ok'); } catch (\Exception $exc) { $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, array(), array(), ''); } $this->_responseWS->response(); }
public function postForm(FormPublicationRequest $request) { $id = $request->input('id', NULL); $message = "Se ingresó correctamente la publicación."; $modelPost = new PuAds(); $data = $request->all(); if ($request->hasfile('picture')) { $validator = Validator::make($request->all(), ['picture' => ['mimes:jpg,png,jpeg']]); if ($validator->fails()) { return redirect(action('Admin\\PublicationController@postForm'))->withErrors($validator)->withInput(); } $file = $request->file('picture'); $nameimage = date('Ymdhis') . rand(1, 1000) . '.' . $file->getClientOriginalExtension(); $file->move(public_path() . "/dinamic/publication/", $nameimage); $pathImage = '/dinamic/publication/' . $nameimage; if (isset($id) && $id != '') { PuPicture::wherePuAdId($id)->forceDelete(); PuPicture::create(['name_picture' => $nameimage, 'url' => $pathImage, 'pu_ad_id' => $id]); } } try { if (isset($id) && $id != '') { $Post = $modelPost->find($id); $Post->fill($data); $Post->save(); $message = "Se actualizó la información de la publicación de manera correcta."; } else { $modelProvider->fill($data); $idPost = $modelPost->save($data); if ($request->hasfile('picture')) { PuPicture::create(['name_picture' => $nameimage, 'url' => $pathImage, 'pu_ad_id' => $idPost]); } } } catch (Exception $ex) { } $url = isset($data['modulo']) ? str_replace("|", "/", $data['modulo']) : self::NAMEC; return redirect('admpanel/' . $url)->with('messageSuccess', $message); }