/**
  * Create a resource
  *
  * @param  mixed $data
  * @return ApiProblem|mixed
  */
 public function create($data)
 {
     $user = $this->userRepository->findByUsername($this->getIdentity()->getRoleId());
     if ($user->getRole() != "admin") {
         return new ApiProblem("403", "The user has not access to this info.");
     }
     return $this->repository->insert((array) $data);
 }
Example #2
0
 /**
  * Create a resource
  *
  * @param  mixed $data
  * @return ApiProblem|mixed
  */
 public function create($data)
 {
     try {
         $this->authService->hasRole('admin');
         return $this->productsRepository->insert($data);
     } catch (\Exception $e) {
         return new ApiProblem($e->getCode(), $e->getMessage());
     }
 }
 /**
  * Create a resource
  *
  * @param  mixed $data
  * @return ApiProblem|mixed
  */
 public function create($data)
 {
     $usuarioLogado = $this->getUsuarioLogado();
     if ($usuarioLogado->getRole() === 'admin') {
         $user = $this->repository->insert($data);
         return $user;
     } else {
         return new ApiProblem(403, "Apenas usuários 'admin' podem adicionar produtos");
     }
 }
 public function insert($data)
 {
     return ['product_id' => $this->productRepository->insert($data)];
 }