original_string: protected function isDuplicate($service, $resource, $value, $key = 'name')
      {
          $api = $service . '/' . $resource;
          switch ($api) {
              case 'system/role':
                  return Role::where($key, $value)->exists();
              case 'system/service':
                  return Service::where($key, $value)->exists();
              case 'system/app':
                  return App::where($key, $value)->exists();
              case 'system/event_script':
              case 'system/custom':
              case 'user/custom':
              case $service . '/_schema':
                  try {
                      $result = ServiceManager::handleRequest($service, Verbs::GET, $resource . '/' . $value);
                      if ($result->getStatusCode() === 404) {
                          return false;
                      }
                      if ($result->getStatusCode() >= 300) {
                          throw ResponseFactory::createExceptionFromResponse($result);
                      }
  
                      $result = $result->getContent();
                      if (is_string($result)) {
                          $result = ['value' => $result];
                      }
                      $result = array_get($result, config('df.resources_wrapper'), $result);
  
                      return (count($result) > 0) ? true : false;
                  } catch (NotFoundException $e) {
                      return false;
                  }
              default:
                  try {
                      $result = ServiceManager::handleRequest($service, Verbs::GET, $resource,
                          ['filter' => "$key = $value"]);
                      if ($result->getStatusCode() === 404) {
                          return false;
                      }
                      if ($result->getStatusCode() >= 300) {
                          throw ResponseFactory::createExceptionFromResponse($result);
                      }
  
                      $result = $result->getContent();
                      if (is_string($result)) {
                          $result = ['value' => $result];
                      }
                      $result = array_get($result, config('df.resources_wrapper'), $result);
  
                      return (count($result) > 0) ? true : false;
                  } catch (NotFoundException $e) {
                      return false;
                  }
          }
      }
code: protected function isDuplicate($service, $resource, $value, $key = 'name')
      {
          $api = $service . '/' . $resource;
          switch ($api) {
              case 'system/role':
                  return Role::where($key, $value)->exists();
              case 'system/service':
                  return Service::where($key, $value)->exists();
              case 'system/app':
                  return App::where($key, $value)->exists();
              case 'system/event_script':
              case 'system/custom':
              case 'user/custom':
              case $service . '/_schema':
                  try {
                      $result = ServiceManager::handleRequest($service, Verbs::GET, $resource . '/' . $value);
                      if ($result->getStatusCode() === 404) {
                          return false;
                      }
                      if ($result->getStatusCode() >= 300) {
                          throw ResponseFactory::createExceptionFromResponse($result);
                      }
  
                      $result = $result->getContent();
                      if (is_string($result)) {
                          $result = ['value' => $result];
                      }
                      $result = array_get($result, config('df.resources_wrapper'), $result);
  
                      return (count($result) > 0) ? true : false;
                  } catch (NotFoundException $e) {
                      return false;
                  }
              default:
                  try {
                      $result = ServiceManager::handleRequest($service, Verbs::GET, $resource,
                          ['filter' => "$key = $value"]);
                      if ($result->getStatusCode() === 404) {
                          return false;
                      }
                      if ($result->getStatusCode() >= 300) {
                          throw ResponseFactory::createExceptionFromResponse($result);
                      }
  
                      $result = $result->getContent();
                      if (is_string($result)) {
                          $result = ['value' => $result];
                      }
                      $result = array_get($result, config('df.resources_wrapper'), $result);
  
                      return (count($result) > 0) ? true : false;
                  } catch (NotFoundException $e) {
                      return false;
                  }
          }
      }
code_tokens: protected function isDuplicate ( $ service , $ resource , $ value , $ key = 'name' ) { $ api = $ service . '/' . $ resource ; switch ( $ api ) { case 'system/role' : return Role :: where ( $ key , $ value ) -> exists ( ) ; case 'system/service' : return Service :: where ( $ key , $ value ) -> exists ( ) ; case 'system/app' : return App :: where ( $ key , $ value ) -> exists ( ) ; case 'system/event_script' : case 'system/custom' : case 'user/custom' : case $ service . '/_schema' : try { $ result = ServiceManager :: handleRequest ( $ service , Verbs :: GET , $ resource . '/' . $ value ) ; if ( $ result -> getStatusCode ( ) === 404 ) { return false ; } if ( $ result -> getStatusCode ( ) >= 300 ) { throw ResponseFactory :: createExceptionFromResponse ( $ result ) ; } $ result = $ result -> getContent ( ) ; if ( is_string ( $ result ) ) { $ result = [ 'value' => $ result ] ; } $ result = array_get ( $ result , config ( 'df.resources_wrapper' ) , $ result ) ; return ( count ( $ result ) > 0 ) ? true : false ; } catch ( NotFoundException $ e ) { return false ; } default : try { $ result = ServiceManager :: handleRequest ( $ service , Verbs :: GET , $ resource , [ 'filter' => "$key = $value" ] ) ; if ( $ result -> getStatusCode ( ) === 404 ) { return false ; } if ( $ result -> getStatusCode ( ) >= 300 ) { throw ResponseFactory :: createExceptionFromResponse ( $ result ) ; } $ result = $ result -> getContent ( ) ; if ( is_string ( $ result ) ) { $ result = [ 'value' => $ result ] ; } $ result = array_get ( $ result , config ( 'df.resources_wrapper' ) , $ result ) ; return ( count ( $ result ) > 0 ) ? true : false ; } catch ( NotFoundException $ e ) { return false ; } } }
docstring: Checks to see if a resource record is a duplicate.
  
  @param string $service
  @param string $resource
  @param mixed  $value
  @param string $key
  
  @return bool
  @throws \DreamFactory\Core\Exceptions\RestException
docstring_tokens: Checks to see if a resource record is a duplicate .