Пример #1
0
 /**
  * Update a resource
  *
  * @param  mixed $id
  * @param  mixed $data
  * @return ApiProblem|mixed
  */
 public function update($id, $data)
 {
     try {
         $this->authService->hasRole('admin');
         return $this->productsRepository->update($id, $data);
     } catch (\Exception $e) {
         return new ApiProblem($e->getCode(), $e->getMessage());
     }
 }
Пример #2
0
 /**
  * Update a resource
  *
  * @param  mixed $id
  * @param  mixed $data
  * @return ApiProblem|mixed
  */
 public function update($id, $data)
 {
     try {
         $this->authService->hasRole(['admin', 'salesman']);
         if ($this->authService->isAdmin()) {
             return $this->usersService->update($id, $data);
         } elseif ((int) $id == $this->authService->getUser()->getId()) {
             if (isset($data->role)) {
                 unset($data->role);
             }
             return $this->usersService->update($id, $data);
         }
         return new ApiProblem(401, 'Access denied');
     } catch (\Exception $e) {
         return new ApiProblem($e->getCode(), $e->getMessage());
     }
 }