public function create(array $data) { try { $this->validator->with($data)->passesOrFail(); return $this->repositoy->create($data); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
public function create(array $data) { // enviar um email // disparar notificacao // postar um tweet try { $this->validator->with($data)->passesOrFail(); return $this->repository->create($data); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
public function create(array $data, $idProject) { try { $data['project_id'] = $idProject; $this->validator->with($data)->passesOrFail(); 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($project_id, array $data) { // enviar email // disparar notificacao $data['project_id'] = $project_id; try { $this->validator->with($data)->passesOrFail(); return $this->repository->create($data); } catch (ValidatorException $e) { return ['error' => true, 'message' => $e->getMessageBag()]; } }
/** * @param array $data * @return \Illuminate\Http\JsonResponse */ public function create(array $data) { try { $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_CREATE); $create = $this->repository->create($data); $msg = "Nota do projeto criada com sucesso."; Log::info($msg); return response()->json(["message" => $msg, "data" => $create->toArray()], 200); } catch (ValidatorException $e) { return response()->json([$e->getMessageBag()], 400); } //QueryException tratado em Exceptions/Handler.php }
public function create(array $data) { try { $this->validator->with($data)->passesOrFail(); if (is_null(Project::find($data['project_id']))) { 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.'); } return $this->repository->create($data); } catch (ValidatorException $e) { return Errors::basic($e->getMessageBag()); } }