src/Execution/DataLoader/ModelRelationFetcher.php
public function loadRelationForPage(int $first, int $page, string $relationName, Closure $relationConstraints): self
    {
        // Load the count of relations of models, this will be the `total` argument of `Paginator`.
        // Be aware that this will reload all the models entirely with the count of their relations,
        // which will bring extra DB queries, always prefer querying without pagination if possible.
        $this->reloadModelsWithRelationCount();

        $relations = $this
            ->buildRelationsFromModels($relationName, $relationConstraints)
            ->map(
                function (Relation $relation) use ($first, $page) {
                    return $relation->forPage($page, $first);
                }
            );

        /** @var \Illuminate\Database\Eloquent\Collection $relationModels */
        $relationModels = $this
            ->unionAllRelationQueries($relations)
            ->get();

        $this->hydratePivotRelation($relationName, $relationModels);

        $this->loadDefaultWith($relationModels);

        $this->associateRelationModels($relationName, $relationModels);

        $this->convertRelationToPaginator($first, $page, $relationName);

        return $this;
    }
public function loadRelationForPage(int $first, int $page, string $relationName, Closure $relationConstraints): self
    {
        // Load the count of relations of models, this will be the `total` argument of `Paginator`.
        // Be aware that this will reload all the models entirely with the count of their relations,
        // which will bring extra DB queries, always prefer querying without pagination if possible.
        $this->reloadModelsWithRelationCount();

        $relations = $this
            ->buildRelationsFromModels($relationName, $relationConstraints)
            ->map(
                function (Relation $relation) use ($first, $page) {
                    return $relation->forPage($page, $first);
                }
            );

        /** @var \Illuminate\Database\Eloquent\Collection $relationModels */
        $relationModels = $this
            ->unionAllRelationQueries($relations)
            ->get();

        $this->hydratePivotRelation($relationName, $relationModels);

        $this->loadDefaultWith($relationModels);

        $this->associateRelationModels($relationName, $relationModels);

        $this->convertRelationToPaginator($first, $page, $relationName);

        return $this;
    }
public function loadRelationForPage ( int $ first , int $ page , string $ relationName , Closure $ relationConstraints ) : self { // Load the count of relations of models, this will be the `total` argument of `Paginator`. // Be aware that this will reload all the models entirely with the count of their relations, // which will bring extra DB queries, always prefer querying without pagination if possible. $ this -> reloadModelsWithRelationCount ( ) ; $ relations = $ this -> buildRelationsFromModels ( $ relationName , $ relationConstraints ) -> map ( function ( Relation $ relation ) use ( $ first , $ page ) { return $ relation -> forPage ( $ page , $ first ) ; } ) ; /** @var \Illuminate\Database\Eloquent\Collection $relationModels */ $ relationModels = $ this -> unionAllRelationQueries ( $ relations ) -> get ( ) ; $ this -> hydratePivotRelation ( $ relationName , $ relationModels ) ; $ this -> loadDefaultWith ( $ relationModels ) ; $ this -> associateRelationModels ( $ relationName , $ relationModels ) ; $ this -> convertRelationToPaginator ( $ first , $ page , $ relationName ) ; return $ this ; }
Load only one page of relations of all the models.

The relation will be converted to a `Paginator` instance.

@param  int  $first
@param  int  $page
@param  string  $relationName
@param  \Closure  $relationConstraints
@return $this
Load only one page of relations of all the models .