public function rebuildCacheRecord(array $config, Model $model, $command, $aggregateField = null)
    {
        $config = $this->processConfig($config);
        $table = $this->getModelTable($model);

        if (is_null($aggregateField)) {
            $aggregateField = $config['foreignKey'];
        } else {
            $aggregateField = snake_case($aggregateField);
        }

        $sql = DB::table($table)->select($config['foreignKey'])->groupBy($config['foreignKey']);

        if (strtolower($command) == 'count') {
            $aggregate = $sql->count($aggregateField);
        } else if (strtolower($command) == 'sum') {
            $aggregate = $sql->sum($aggregateField);
        } else if (strtolower($command) == 'avg') {
            $aggregate = $sql->avg($aggregateField);
        } else {
            $aggregate = null;
        }

        return DB::table($config['table'])
            ->update([
                $config['field'] => $aggregate
            ]);
    }
public function rebuildCacheRecord(array $config, Model $model, $command, $aggregateField = null)
    {
        $config = $this->processConfig($config);
        $table = $this->getModelTable($model);

        if (is_null($aggregateField)) {
            $aggregateField = $config['foreignKey'];
        } else {
            $aggregateField = snake_case($aggregateField);
        }

        $sql = DB::table($table)->select($config['foreignKey'])->groupBy($config['foreignKey']);

        if (strtolower($command) == 'count') {
            $aggregate = $sql->count($aggregateField);
        } else if (strtolower($command) == 'sum') {
            $aggregate = $sql->sum($aggregateField);
        } else if (strtolower($command) == 'avg') {
            $aggregate = $sql->avg($aggregateField);
        } else {
            $aggregate = null;
        }

        return DB::table($config['table'])
            ->update([
                $config['field'] => $aggregate
            ]);
    }
public function rebuildCacheRecord ( array $ config , Model $ model , $ command , $ aggregateField = null ) { $ config = $ this -> processConfig ( $ config ) ; $ table = $ this -> getModelTable ( $ model ) ; if ( is_null ( $ aggregateField ) ) { $ aggregateField = $ config [ 'foreignKey' ] ; } else { $ aggregateField = snake_case ( $ aggregateField ) ; } $ sql = DB :: table ( $ table ) -> select ( $ config [ 'foreignKey' ] ) -> groupBy ( $ config [ 'foreignKey' ] ) ; if ( strtolower ( $ command ) == 'count' ) { $ aggregate = $ sql -> count ( $ aggregateField ) ; } else if ( strtolower ( $ command ) == 'sum' ) { $ aggregate = $ sql -> sum ( $ aggregateField ) ; } else if ( strtolower ( $ command ) == 'avg' ) { $ aggregate = $ sql -> avg ( $ aggregateField ) ; } else { $ aggregate = null ; } return DB :: table ( $ config [ 'table' ] ) -> update ( [ $ config [ 'field' ] => $ aggregate ] ) ; }
Rebuilds the cache for the records in question.

@param array $config
@param Model $model
@param $command
@param null $aggregateField
@return mixed
Rebuilds the cache for the records in question .