public function update(array $data, $id) { try { $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_UPDATE); return $this->repository->update($data, $id); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { try { if (!$this->service->checkProjectOwner($id)) { return $this->erroMsgm("O usuário não é onwer desse projeto"); } return $this->repository->update($request->all(), $id); } catch (ModelNotFoundException $e) { return $this->erroMsgm('Projeto não encontrado.'); } catch (NoActiveAccessTokenException $e) { return $this->erroMsgm('Usuário não está logado.'); } catch (\Exception $e) { return $this->erroMsgm('Ocorreu um erro ao atualizar o projeto.'); } }
public function update(array $data, $file_id) { $file = ProjectFile::find($file_id); if (is_null($file)) { return Errors::invalidId($file_id); } try { $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_UPDATE); if ($data['project_id'] != $file->project_id) { return Errors::basic('Você não pode alterar o projeto do arquivo.'); } if ($data['extension'] != $file->extension) { return Errors::basic('Você não pode alterar a extensão do arquivo.'); } $user_id = \Authorizer::getResourceOwnerId(); if (!$this->projectRepository->isMember($file->project_id, $user_id)) { return Errors::basic('Acesso negado. Você não é membro do projeto selecionado.'); } return $this->repository->update($data, $file_id); } catch (ValidatorException $e) { return Errors::basic($e->getMessageBag()); } }