src/Execution/DataLoader/ModelRelationFetcher.php
protected function unionAllRelationQueries(Collection $relations): EloquentBuilder
    {
        return $relations
            ->reduce(
                function (EloquentBuilder $builder, Relation $relation) {
                    return $builder->unionAll(
                        $relation->getQuery()
                    );
                },
                // Use the first query as the initial starting point
                $relations->shift()->getQuery()
            );
    }
protected function unionAllRelationQueries(Collection $relations): EloquentBuilder
    {
        return $relations
            ->reduce(
                function (EloquentBuilder $builder, Relation $relation) {
                    return $builder->unionAll(
                        $relation->getQuery()
                    );
                },
                // Use the first query as the initial starting point
                $relations->shift()->getQuery()
            );
    }
protected function unionAllRelationQueries ( Collection $ relations ) : EloquentBuilder { return $ relations -> reduce ( function ( EloquentBuilder $ builder , Relation $ relation ) { return $ builder -> unionAll ( $ relation -> getQuery ( ) ) ; } , // Use the first query as the initial starting point $ relations -> shift ( ) -> getQuery ( ) ) ; }
Merge all the relation queries into a single query with UNION ALL.

@param  \Illuminate\Support\Collection  $relations
@return \Illuminate\Database\Eloquent\Builder
Merge all the relation queries into a single query with UNION ALL .