src/Versatile/Introspection/EloquentPathIntrospector.php
public function classOfPath($rootObject, $path)
    {

        $rootObject = $this->rootInstance($rootObject);
        $cacheId = $this->getCacheId($rootObject, $path);

        if (isset($this->cache[$cacheId])) {
            return $this->cache[$cacheId];
        }

        $parts = $this->parser->splitPath($path);

        $partCount = count($parts);
        $last = $partCount-1;

        $currentObject = $rootObject;

        for ($i=0; $i<$partCount; $i++) {

            $part = $parts[$i];

            $methodName = '';

            if (method_exists($currentObject, $part)) {
                $methodName = $part;
            } else {
                $camelMethod = camel_case($part);
                if(method_exists($currentObject, $camelMethod)){
                    $methodName = $camelMethod;
                }
            }

            if(!$methodName){
                continue;
            }

            $reflectionMethod = new ReflectionMethod($currentObject, $methodName);

            if ($reflectionMethod->isStatic() || !$reflectionMethod->isPublic() ||
                $reflectionMethod->isAbstract()) {
                continue;
            }


            $relation = $currentObject->{$methodName}();

            if ($relation instanceof Relation) {

                if (!$model = $relation->getQuery()->getModel()) {
                    continue;
                }

                if($i != $last){
                    $currentObject = $model;
                    continue;
                }

                $this->cache[$cacheId] = get_class($model);
                return $this->cache[$cacheId];
            }

        }

        throw new UnexpectedValueException("$path does not point to an relation");
    }
public function classOfPath($rootObject, $path)
    {

        $rootObject = $this->rootInstance($rootObject);
        $cacheId = $this->getCacheId($rootObject, $path);

        if (isset($this->cache[$cacheId])) {
            return $this->cache[$cacheId];
        }

        $parts = $this->parser->splitPath($path);

        $partCount = count($parts);
        $last = $partCount-1;

        $currentObject = $rootObject;

        for ($i=0; $i<$partCount; $i++) {

            $part = $parts[$i];

            $methodName = '';

            if (method_exists($currentObject, $part)) {
                $methodName = $part;
            } else {
                $camelMethod = camel_case($part);
                if(method_exists($currentObject, $camelMethod)){
                    $methodName = $camelMethod;
                }
            }

            if(!$methodName){
                continue;
            }

            $reflectionMethod = new ReflectionMethod($currentObject, $methodName);

            if ($reflectionMethod->isStatic() || !$reflectionMethod->isPublic() ||
                $reflectionMethod->isAbstract()) {
                continue;
            }


            $relation = $currentObject->{$methodName}();

            if ($relation instanceof Relation) {

                if (!$model = $relation->getQuery()->getModel()) {
                    continue;
                }

                if($i != $last){
                    $currentObject = $model;
                    continue;
                }

                $this->cache[$cacheId] = get_class($model);
                return $this->cache[$cacheId];
            }

        }

        throw new UnexpectedValueException("$path does not point to an relation");
    }
{@inheritdoc}

@param string|object $rootObject The root object
@param string $path The path relative from root
@return string classname of class related by $path