示例#1
0
 /**
  * Updates Files into database.
  *
  * @param Files $files
  * @param array $input
  *
  * @return Files
  */
 public function update($files, $input)
 {
     if (isset($input['location'])) {
         $savedFile = FileService::saveFile($input['location'], 'files/');
         $_file = $input['location'];
         $fileInput = $input;
         $fileInput['name'] = $savedFile['original'];
         $fileInput['location'] = $savedFile['name'];
         $fileInput['mime'] = $_file->getClientMimeType();
         $fileInput['size'] = $_file->getClientSize();
     } else {
         $fileInput = $input;
     }
     $fileInput['is_published'] = isset($input['is_published']) ? (bool) $input['is_published'] : 0;
     return $files->update($fileInput);
 }
示例#2
0
 /**
  * Updates Images into database.
  *
  * @param Images $images
  * @param array  $input
  *
  * @return Images
  */
 public function update($images, $input)
 {
     if (isset($input['location']) && !empty($input['location'])) {
         $savedFile = FileService::saveFile($input['location'], 'images/');
         if (!$savedFile) {
             Quarx::notification('Image could not be updated.', 'danger');
             return false;
         }
         $input['location'] = $savedFile['name'];
         $input['original_name'] = $savedFile['original'];
     } else {
         $input['location'] = $images->location;
     }
     if (!isset($input['is_published'])) {
         $input['is_published'] = 0;
     } else {
         $input['is_published'] = 1;
     }
     return $images->update($input);
 }
示例#3
0
 /**
  * Store a newly created Files in storage.
  *
  * @param FileRequest $request
  *
  * @return Response
  */
 public function upload(Request $request)
 {
     $validation = ValidationService::check(['location' => []]);
     if (!$validation['errors']) {
         $file = $request->file('location');
         $fileSaved = FileService::saveFile($file, 'files/');
         $fileSaved['name'] = CryptoService::encrypt($fileSaved['name']);
         $fileSaved['mime'] = $file->getClientMimeType();
         $fileSaved['size'] = $file->getClientSize();
         $response = QuarxResponseService::apiResponse('success', $fileSaved);
     } else {
         $response = QuarxResponseService::apiErrorResponse($validation['errors'], $validation['inputs']);
     }
     return $response;
 }