src/Traits/LoopsOverRelations.php
protected function fetchRelationValue($eloquent, $name, array $relations = [], $format = false)
    {
        $object = clone $eloquent;
        while ($relation = array_shift($relations)) {
            // Treat (Has)Many(ToMany|Through) listing relations as "count()" subQuery.
            if ($this->isCountableRelation($relation)) {
                return present($object, $name, $object->$name()->count());
            }

            $object = call_user_func([$orig = $object, $relation]);

            // Treat BelongsToMany form relation as array of values.
            if ($object instanceof BelongsToMany) {
                return array_map(
                    'intval',
                    \DB::table($object->getTable())
                       ->where($this->getQualifiedForeignKeyName($object), $orig->getKey())
                       ->pluck($this->getQualifiedRelatedKeyName($object))
                       ->toArray()
                );
            }

            $object = $object->getResults();
        }

        return ($object && is_object($object))
            ? ($format ? \admin\helpers\eloquent_attribute($object, $name) : $object->$name)
            : null;
    }
protected function fetchRelationValue($eloquent, $name, array $relations = [], $format = false)
    {
        $object = clone $eloquent;
        while ($relation = array_shift($relations)) {
            // Treat (Has)Many(ToMany|Through) listing relations as "count()" subQuery.
            if ($this->isCountableRelation($relation)) {
                return present($object, $name, $object->$name()->count());
            }

            $object = call_user_func([$orig = $object, $relation]);

            // Treat BelongsToMany form relation as array of values.
            if ($object instanceof BelongsToMany) {
                return array_map(
                    'intval',
                    \DB::table($object->getTable())
                       ->where($this->getQualifiedForeignKeyName($object), $orig->getKey())
                       ->pluck($this->getQualifiedRelatedKeyName($object))
                       ->toArray()
                );
            }

            $object = $object->getResults();
        }

        return ($object && is_object($object))
            ? ($format ? \admin\helpers\eloquent_attribute($object, $name) : $object->$name)
            : null;
    }
protected function fetchRelationValue ( $ eloquent , $ name , array $ relations = [ ] , $ format = false ) { $ object = clone $ eloquent ; while ( $ relation = array_shift ( $ relations ) ) { // Treat (Has)Many(ToMany|Through) listing relations as "count()" subQuery. if ( $ this -> isCountableRelation ( $ relation ) ) { return present ( $ object , $ name , $ object -> $ name ( ) -> count ( ) ) ; } $ object = call_user_func ( [ $ orig = $ object , $ relation ] ) ; // Treat BelongsToMany form relation as array of values. if ( $ object instanceof BelongsToMany ) { return array_map ( 'intval' , \ DB :: table ( $ object -> getTable ( ) ) -> where ( $ this -> getQualifiedForeignKeyName ( $ object ) , $ orig -> getKey ( ) ) -> pluck ( $ this -> getQualifiedRelatedKeyName ( $ object ) ) -> toArray ( ) ) ; } $ object = $ object -> getResults ( ) ; } return ( $ object && is_object ( $ object ) ) ? ( $ format ? \ admin \ helpers \ eloquent_attribute ( $ object , $ name ) : $ object -> $ name ) : null ; }
Loops over provided relations to fetch value.

@param        $eloquent
@param string $name
@param array $relations
@param bool $format

@throws Exception

@return mixed
Loops over provided relations to fetch value .