public function scopeWithRelations(Builder $builder, $relations = null)
    {
        $with = [];
        foreach ($this->getWithRelationsList($relations) as $relation) {
            list($relation, $scope) = $this->_parseRelation($relation);

            if ($this->isWithableRelation($builder, $relation)) {
                if ($scope) {
                    $with[$relation] = function ($query) use ($scope) {
                        $query->$scope();
                    };
                } else {
                    $with[] = $relation;
                }
            }
        }
        $builder->with($with);
    }
public function scopeWithRelations(Builder $builder, $relations = null)
    {
        $with = [];
        foreach ($this->getWithRelationsList($relations) as $relation) {
            list($relation, $scope) = $this->_parseRelation($relation);

            if ($this->isWithableRelation($builder, $relation)) {
                if ($scope) {
                    $with[$relation] = function ($query) use ($scope) {
                        $query->$scope();
                    };
                } else {
                    $with[] = $relation;
                }
            }
        }
        $builder->with($with);
    }
public function scopeWithRelations ( Builder $ builder , $ relations = null ) { $ with = [ ] ; foreach ( $ this -> getWithRelationsList ( $ relations ) as $ relation ) { list ( $ relation , $ scope ) = $ this -> _parseRelation ( $ relation ) ; if ( $ this -> isWithableRelation ( $ builder , $ relation ) ) { if ( $ scope ) { $ with [ $ relation ] = function ( $ query ) use ( $ scope ) { $ query -> $ scope ( ) ; } ; } else { $ with [ ] = $ relation ; } } } $ builder -> with ( $ with ) ; }
Add eager loaded relations.

@param Builder $builder query builder
@param array $relations list of relations to be loaded
Add eager loaded relations .