protected function resolveNestedRelations($data):array
    {
        if (is_null($data)) {
            return [];
        }

        $data = $data instanceof Model ? [$data] : $data;

        return collect($data)->flatMap(function ($model) {
            $relations = collect($model->getRelations());

            return $relations->keys()->merge($relations->flatMap(function ($relation, $key) {
                return collect($this->resolveNestedRelations($relation))->map(function ($nestedRelation) use ($key) {
                    return $key . '.' . $nestedRelation;
                });
            }));
        })->unique()->toArray();
    }
protected function resolveNestedRelations($data):array
    {
        if (is_null($data)) {
            return [];
        }

        $data = $data instanceof Model ? [$data] : $data;

        return collect($data)->flatMap(function ($model) {
            $relations = collect($model->getRelations());

            return $relations->keys()->merge($relations->flatMap(function ($relation, $key) {
                return collect($this->resolveNestedRelations($relation))->map(function ($nestedRelation) use ($key) {
                    return $key . '.' . $nestedRelation;
                });
            }));
        })->unique()->toArray();
    }
protected function resolveNestedRelations ( $ data ) : array { if ( is_null ( $ data ) ) { return [ ] ; } $ data = $ data instanceof Model ? [ $ data ] : $ data ; return collect ( $ data ) -> flatMap ( function ( $ model ) { $ relations = collect ( $ model -> getRelations ( ) ) ; return $ relations -> keys ( ) -> merge ( $ relations -> flatMap ( function ( $ relation , $ key ) { return collect ( $ this -> resolveNestedRelations ( $ relation ) ) -> map ( function ( $ nestedRelation ) use ( $ key ) { return $ key . '.' . $ nestedRelation ; } ) ; } ) ) ; } ) -> unique ( ) -> toArray ( ) ; }
Resolve eager loaded relations from the model including any nested relations.

@param  \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model $data
@return array
Resolve eager loaded relations from the model including any nested relations .