public function create(array $data) { try { $this->validator->with($data)->passesOrFail(); return $this->repository->create($data); } catch (ValidatorException $e) { return Errors::basic($e->getMessageBag()); } }
public function update(array $data, $id) { try { $this->validator->with($data)->passesOrFail(); return $this->repository->update($data, $id); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
public function addMember(array $data) { try { $this->projectMemberValidator->with($data)->passesOrFail(); return $this->projectMemberRepository->create($data); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
public function addMember(array $data) { try { $this->memberValidator->with($data)->passesOrFail(); $project = $this->repository->find($data['project_id']); return $project->members()->attach($data['member_id']); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
public function create(array $data) { try { $this->validator->with($data)->passesOrFail(); $this->setPresenter(); return $this->repository->create($data); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } catch (\Exception $e) { return ['error' => true, 'message' => $e->getMessage()]; } }
public function create(array $data) { try { $this->validator->with($data)->passesOrFail(); $aux = $this->repository->skipPresenter()->findWhere(['user_id' => $data['user_id'], 'project_id' => $data['project_id']]); if (count($aux) > 0) { return Errors::basic("Falha. Este usuario ja eh membro deste projeto"); } return $this->repository->create($data); } catch (ValidatorException $e) { return Errors::basic($e->getMessageBag()); } }
/** * @param array $data * @return \Illuminate\Http\JsonResponse */ public function add(array $data) { try { $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_CREATE); $create = $this->repository->create($data); $msg = "Membro adicionado com sucesso."; Log::info($msg); return response()->json(["message" => $msg, "data" => $create->toArray()]); } catch (ValidatorException $e) { return response()->json([$e->getMessageBag()], 400); } //QueryException tratado em Exceptions/Handler.php }
public function update(array $data, $id) { try { $this->validator->with($data)->passesOrFail(); //return $this->repository->update($data, $id); if ($this->repository->update($data, $id)) { return ['success' => true, 'message' => 'Tarefa atualizada com sucesso!']; } } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } catch (ModelNotFoundException $e) { return ['error' => true, 'message' => 'Não foi possível atualizar o membro! Projeto ou membro não encontrado!']; } }