protected function getValueFromObject($instance, $name)
    {
        if ($name instanceof Closure) {
            return $name($instance);
        }

        /*
         * Implement json parsing
         */
        if (strpos($name, '.') === false && strpos($name, '->') !== false) {
            $casts = collect($instance->getCasts());
            $jsonParts = collect(explode('->', $name));

            $jsonAttr = $instance->{$jsonParts->first()};

            $cast = $casts->get($jsonParts->first(), false);

            if ($cast == 'object') {
                $jsonAttr = json_decode(json_encode($jsonAttr), true);
            } elseif ($cast != 'array') {
                $jsonAttr = json_decode($jsonAttr);
            }

            return Arr::get($jsonAttr, $jsonParts->slice(1)->implode('.'));
        }

        $parts = explode('.', $name);
        $part = array_shift($parts);

        if ($instance instanceof Collection) {
            $instance = $instance->pluck($part);
        } elseif ($instance instanceof SuportCollection) {
            $instance = $instance->first();
            if ($instance instanceof Collection) {
                $instance = $instance->pluck($part);
            }

            if ($instance === null) {
                $instance = collect();
            }
        } elseif (! is_null($instance)) {
            $instance = $instance->getAttribute($part);
        }

        if (! empty($parts) && ! is_null($instance)) {
            return $this->getValueFromObject($instance, implode('.', $parts));
        }

        return $instance;
    }
protected function getValueFromObject($instance, $name)
    {
        if ($name instanceof Closure) {
            return $name($instance);
        }

        /*
         * Implement json parsing
         */
        if (strpos($name, '.') === false && strpos($name, '->') !== false) {
            $casts = collect($instance->getCasts());
            $jsonParts = collect(explode('->', $name));

            $jsonAttr = $instance->{$jsonParts->first()};

            $cast = $casts->get($jsonParts->first(), false);

            if ($cast == 'object') {
                $jsonAttr = json_decode(json_encode($jsonAttr), true);
            } elseif ($cast != 'array') {
                $jsonAttr = json_decode($jsonAttr);
            }

            return Arr::get($jsonAttr, $jsonParts->slice(1)->implode('.'));
        }

        $parts = explode('.', $name);
        $part = array_shift($parts);

        if ($instance instanceof Collection) {
            $instance = $instance->pluck($part);
        } elseif ($instance instanceof SuportCollection) {
            $instance = $instance->first();
            if ($instance instanceof Collection) {
                $instance = $instance->pluck($part);
            }

            if ($instance === null) {
                $instance = collect();
            }
        } elseif (! is_null($instance)) {
            $instance = $instance->getAttribute($part);
        }

        if (! empty($parts) && ! is_null($instance)) {
            return $this->getValueFromObject($instance, implode('.', $parts));
        }

        return $instance;
    }
protected function getValueFromObject ( $ instance , $ name ) { if ( $ name instanceof Closure ) { return $ name ( $ instance ) ; } /*
         * Implement json parsing
         */ if ( strpos ( $ name , '.' ) === false && strpos ( $ name , '->' ) !== false ) { $ casts = collect ( $ instance -> getCasts ( ) ) ; $ jsonParts = collect ( explode ( '->' , $ name ) ) ; $ jsonAttr = $ instance -> { $ jsonParts -> first ( ) } ; $ cast = $ casts -> get ( $ jsonParts -> first ( ) , false ) ; if ( $ cast == 'object' ) { $ jsonAttr = json_decode ( json_encode ( $ jsonAttr ) , true ) ; } elseif ( $ cast != 'array' ) { $ jsonAttr = json_decode ( $ jsonAttr ) ; } return Arr :: get ( $ jsonAttr , $ jsonParts -> slice ( 1 ) -> implode ( '.' ) ) ; } $ parts = explode ( '.' , $ name ) ; $ part = array_shift ( $ parts ) ; if ( $ instance instanceof Collection ) { $ instance = $ instance -> pluck ( $ part ) ; } elseif ( $ instance instanceof SuportCollection ) { $ instance = $ instance -> first ( ) ; if ( $ instance instanceof Collection ) { $ instance = $ instance -> pluck ( $ part ) ; } if ( $ instance === null ) { $ instance = collect ( ) ; } } elseif ( ! is_null ( $ instance ) ) { $ instance = $ instance -> getAttribute ( $ part ) ; } if ( ! empty ( $ parts ) && ! is_null ( $ instance ) ) { return $ this -> getValueFromObject ( $ instance , implode ( '.' , $ parts ) ) ; } return $ instance ; }
Get column value from instance.

@param Collection|Model|Closure $instance
@param string $name

@return mixed
Get column value from instance .