public function postImageProviderPremium(Request $request) { $result = array('state' => 0, 'msg' => ''); try { $dataImageProvider = $request->all(); $prPictureTotal = PrPictures::wherePrProviderId($dataImageProvider['pr_provider_id'])->select(DB::raw('COUNT(id) as total'))->first(); if ($prPictureTotal->total >= 4) { $result['msg'] = 'Ya no puede subir más imagenes'; return response()->json($result); } if (!$dataImageProvider['pr_provider_id']) { throw new \Exception("Id de proveedor vacio"); } if (isset($dataImageProvider['picture_provider'])) { $file = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $dataImageProvider['picture_provider'])); $dataPicture['name_picture'] = date('YmdHis') . rand(1, 1000) . ".jpg"; $pathrelative = "/dinamic/providers-data/" . $dataPicture['name_picture']; $path = App::publicPath() . $pathrelative; file_put_contents($path, $file); $dataPicture['url'] = $pathrelative; $dataPicture['pr_provider_id'] = $dataImageProvider['pr_provider_id']; $objImageProvider = PrPictures::create($dataPicture); } $result['data'] = ['id' => $objImageProvider->id]; $result['state'] = 1; } catch (\Exception $exc) { $result['msg'] = $exc->getMessage(); } return response()->json($result); }