public function loadCount($relations)
    {
        if ($this->isEmpty()) {
            return $this;
        }

        $models = $this->first()->newModelQuery()
            ->whereKey($this->modelKeys())
            ->select($this->first()->getKeyName())
            ->withCount(...func_get_args())
            ->get();

        $attributes = Arr::except(
            array_keys($models->first()->getAttributes()),
            $models->first()->getKeyName()
        );

        $models->each(function ($model) use ($attributes) {
            $this->find($model->getKey())->forceFill(
                Arr::only($model->getAttributes(), $attributes)
            )->syncOriginalAttributes($attributes);
        });

        return $this;
    }
public function loadCount($relations)
    {
        if ($this->isEmpty()) {
            return $this;
        }

        $models = $this->first()->newModelQuery()
            ->whereKey($this->modelKeys())
            ->select($this->first()->getKeyName())
            ->withCount(...func_get_args())
            ->get();

        $attributes = Arr::except(
            array_keys($models->first()->getAttributes()),
            $models->first()->getKeyName()
        );

        $models->each(function ($model) use ($attributes) {
            $this->find($model->getKey())->forceFill(
                Arr::only($model->getAttributes(), $attributes)
            )->syncOriginalAttributes($attributes);
        });

        return $this;
    }
public function loadCount ( $ relations ) { if ( $ this -> isEmpty ( ) ) { return $ this ; } $ models = $ this -> first ( ) -> newModelQuery ( ) -> whereKey ( $ this -> modelKeys ( ) ) -> select ( $ this -> first ( ) -> getKeyName ( ) ) -> withCount ( ... func_get_args ( ) ) -> get ( ) ; $ attributes = Arr :: except ( array_keys ( $ models -> first ( ) -> getAttributes ( ) ) , $ models -> first ( ) -> getKeyName ( ) ) ; $ models -> each ( function ( $ model ) use ( $ attributes ) { $ this -> find ( $ model -> getKey ( ) ) -> forceFill ( Arr :: only ( $ model -> getAttributes ( ) , $ attributes ) ) -> syncOriginalAttributes ( $ attributes ) ; } ) ; return $ this ; }
Load a set of relationship counts onto the collection.

@param  array|string  $relations
@return $this
Load a set of relationship counts onto the collection .