src/Execution/DataLoader/ModelRelationFetcher.php
protected function hydratePivotRelation(string $relationName, EloquentCollection $relationModels): self
    {
        $relation = $this->getRelationInstance($relationName);

        if ($relationModels->isNotEmpty() && method_exists($relation, 'hydratePivotRelation')) {
            $hydrationMethod = new ReflectionMethod(get_class($relation), 'hydratePivotRelation');
            $hydrationMethod->setAccessible(true);
            $hydrationMethod->invoke($relation, $relationModels->all());
        }

        return $this;
    }
protected function hydratePivotRelation(string $relationName, EloquentCollection $relationModels): self
    {
        $relation = $this->getRelationInstance($relationName);

        if ($relationModels->isNotEmpty() && method_exists($relation, 'hydratePivotRelation')) {
            $hydrationMethod = new ReflectionMethod(get_class($relation), 'hydratePivotRelation');
            $hydrationMethod->setAccessible(true);
            $hydrationMethod->invoke($relation, $relationModels->all());
        }

        return $this;
    }
protected function hydratePivotRelation ( string $ relationName , EloquentCollection $ relationModels ) : self { $ relation = $ this -> getRelationInstance ( $ relationName ) ; if ( $ relationModels -> isNotEmpty ( ) && method_exists ( $ relation , 'hydratePivotRelation' ) ) { $ hydrationMethod = new ReflectionMethod ( get_class ( $ relation ) , 'hydratePivotRelation' ) ; $ hydrationMethod -> setAccessible ( true ) ; $ hydrationMethod -> invoke ( $ relation , $ relationModels -> all ( ) ) ; } return $ this ; }
Ensure the pivot relation is hydrated too, if it exists.

@param  string  $relationName
@param  \Illuminate\Database\Eloquent\Collection<\Illuminate\Database\Eloquent\Model>  $relationModels
@return $this
Ensure the pivot relation is hydrated too if it exists .