Example #1
0
 public function store($input)
 {
     $files = $this->getInputFiles();
     if (empty($files)) {
         return $this->listener->errorResponse('No input files');
     }
     if (Input::has('type') && Input::has('id')) {
         $validator = Validator::make($input, ['type' => 'required', 'id' => 'required', 'path' => 'required']);
         $property = Input::get('property', 'assets');
         if ($validator->fails()) {
             return $this->listener->errorResponse($validator->errors()->all());
         }
         $type = ucfirst(Input::get('type'));
         $id = Input::get('id');
         $item = $type::withTrashed()->whereId($id)->first();
         if ($item == NULL) {
             return $this->statusResponse(['error' => 'No item found']);
         }
     }
     $validator = Validator::make($input, ['user_id' => 'required']);
     if ($validator->fails()) {
         return $this->listener->errorResponse($validator->errors()->all());
     }
     $assets = [];
     foreach ($files as $f) {
         $asset = new Asset();
         $asset->path = Input::get('path', $this->getPathForFile($f));
         if (Input::has('tag')) {
             $asset->tag = Str::slug(strtolower(Input::get('tag')));
         }
         if (Input::has('shared')) {
             $asset->shared = Input::get('shared') == 'on' ? 1 : 0;
         }
         $user = User::findFromData($input['user_id']);
         $asset->user()->associate($user);
         $asset->saveFile($f);
         array_push($assets, $asset);
     }
     return $this->listener->statusResponse(['notice' => 'Asset Created', 'asset' => $assets]);
     $replace = false;
     if (array_key_exists('replace', $input) && bool_val($input['replace']) === true) {
         $replace = true;
     }
     $rights = Input::get('rights', Asset::ASSET_RIGHTS_UNKNOWN);
     $photos_response = $this->addPhotosToItem($this->getInputFiles(), $item, Input::get('path'), $replace, $rights);
     return $this->listener->statusResponse(['notice' => 'Asset Created', 'asset' => $asset]);
 }