public function createFile(array $data)
 {
     try {
         $this->validator->with($data)->passesOrFail();
         $this->storage->put($data['name'] . '.' . $data['extension'], $this->filesystem->get($data['file']));
         return $this->repository->create($data);
     } catch (ValidatorException $e) {
         return ['error' => true, 'message' => $e->getMessageBag()];
     }
 }
예제 #2
0
 public function createFile(array $data)
 {
     try {
         $this->validator->with($data)->passesOrFail();
         $project = Project::find($data['project_id']);
         if (is_null($project)) {
             return Errors::invalidId($data['project_id']);
         }
         $user_id = \Authorizer::getResourceOwnerId();
         if (!$this->projectRepository->isMember($data['project_id'], $user_id)) {
             return Errors::basic('Acesso negado. Você não é membro do projeto selecionado.');
         }
         $data['extension'] = $data['file']->getClientOriginalExtension();
         $projectFile = $this->repository->create($data);
         $nome = $projectFile->id . "." . $data['extension'];
         $arquivo = $this->filesystem->get($data['file']);
         $this->storage->put($nome, $arquivo);
         return ['message' => 'Arquivo criado'];
     } catch (ValidatorException $e) {
         return Errors::basic($e->getMessageBag());
     }
 }