src/BaseRepositoryEloquent.php
protected function eagerLoadRelations()
    {
        $query = $this->model;

        if (is_array($this->eagerLoadRelations)) {
            $eagerLoads = [];

            foreach ($this->eagerLoadRelations as $relation => $rules) {
                // case for relations[]=relation_name
                // with relation that is numeric
                $relation = (is_integer($relation)) ? $rules : $relation;

                // case for relations[relation_name][attributes][]=attrib_name
                // with relation that is a relation name
                if (is_array($rules) && array_key_exists('attributes', $rules)) {
                    $eagerLoads[$relation] = function ($q) use ($rules) {
                        // If query is instance of HasOneOrMany,
                        // make sure to select the parent key name as foreign key.
                        if (
                            $q instanceof HasOneOrMany &&
                            !in_array($fk = $q->getParent()->getForeignKey(), $rules['attributes'])
                        ) {
                            array_push($rules['attributes'], $fk);
                        }

                        $q->select($rules['attributes']);
                    };
                } else {
                    array_push($eagerLoads, $relation);
                }
            }

            return $query->with($eagerLoads);
        }

        return $query->with($this->eagerLoadRelations);
    }
protected function eagerLoadRelations()
    {
        $query = $this->model;

        if (is_array($this->eagerLoadRelations)) {
            $eagerLoads = [];

            foreach ($this->eagerLoadRelations as $relation => $rules) {
                // case for relations[]=relation_name
                // with relation that is numeric
                $relation = (is_integer($relation)) ? $rules : $relation;

                // case for relations[relation_name][attributes][]=attrib_name
                // with relation that is a relation name
                if (is_array($rules) && array_key_exists('attributes', $rules)) {
                    $eagerLoads[$relation] = function ($q) use ($rules) {
                        // If query is instance of HasOneOrMany,
                        // make sure to select the parent key name as foreign key.
                        if (
                            $q instanceof HasOneOrMany &&
                            !in_array($fk = $q->getParent()->getForeignKey(), $rules['attributes'])
                        ) {
                            array_push($rules['attributes'], $fk);
                        }

                        $q->select($rules['attributes']);
                    };
                } else {
                    array_push($eagerLoads, $relation);
                }
            }

            return $query->with($eagerLoads);
        }

        return $query->with($this->eagerLoadRelations);
    }
protected function eagerLoadRelations ( ) { $ query = $ this -> model ; if ( is_array ( $ this -> eagerLoadRelations ) ) { $ eagerLoads = [ ] ; foreach ( $ this -> eagerLoadRelations as $ relation => $ rules ) { // case for relations[]=relation_name // with relation that is numeric $ relation = ( is_integer ( $ relation ) ) ? $ rules : $ relation ; // case for relations[relation_name][attributes][]=attrib_name // with relation that is a relation name if ( is_array ( $ rules ) && array_key_exists ( 'attributes' , $ rules ) ) { $ eagerLoads [ $ relation ] = function ( $ q ) use ( $ rules ) { // If query is instance of HasOneOrMany, // make sure to select the parent key name as foreign key. if ( $ q instanceof HasOneOrMany && ! in_array ( $ fk = $ q -> getParent ( ) -> getForeignKey ( ) , $ rules [ 'attributes' ] ) ) { array_push ( $ rules [ 'attributes' ] , $ fk ) ; } $ q -> select ( $ rules [ 'attributes' ] ) ; } ; } else { array_push ( $ eagerLoads , $ relation ) ; } } return $ query -> with ( $ eagerLoads ) ; } return $ query -> with ( $ this -> eagerLoadRelations ) ; }
Eagerload relations.

@return \Illuminate\Database\Eloquent\Builder|\Eloquent
Eagerload relations .