/** * * @return Response */ public function store(RegisterPublicationRequest $request) { try { $dataAds = $request->all(); $dataAds['user_id'] = $this->_identity->id; $dataAds['date_publish'] = date("Y-m-d H:i:s"); $dataAds['date_expired'] = date("Y-m-d H:i:s"); if (isset($dataAds['pr_provider_id'])) { if ($dataAds['pr_provider_id'] == 0 || $dataAds['pr_provider_id'] == '') { unset($dataAds['pr_provider_id']); } } $objAds = PuAds::create($dataAds); if (isset($dataAds['picture'])) { $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) { dd($exc->getMessage()); $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, array(), array(), ''); } $this->_responseWS->response(); }