/**
  * File Upload Action
  *
  * @param $parentSection
  * @param $parentId
  * @param null $id
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function fileUploadAction($parentSection, $parentId, $id = null)
 {
     try {
         $fileService = new ApiFileService($parentSection, $parentId);
         $data = $fileService->handleImages($id);
         $this->response->setContent($data)->setStatus(200);
     } catch (Exception $e) {
         $this->response->setContent($e->getMessage())->setStatus($e->getCode());
     }
     return response()->json($this->response->getContent(), $this->response->getStatus());
 }
Example #2
0
 /**
  * Delete
  *
  * @param $section
  * @param $id
  * @throws Exception
  *
  * @return string
  */
 public function delete($section, $id)
 {
     try {
         if ($section == 'image') {
             $fileService = new ApiFileService(null, null);
             $fileService->handleImageDelete($id);
         } else {
             $model = $this->setClass($section);
             $model->findOrFail($id)->delete();
         }
     } catch (Exception $e) {
         if (gettype($e->getCode()) == 'string' || $e->getCode() == 0) {
             throw new \Exception($e->getMessage(), 400);
         }
         throw new Exception($e->getMessage(), $e->getCode());
     }
     return $section . ' with id ' . $id . ' deleted';
 }