public static function bootSummable()
    {
        static::created(function ($model) {
            $sumCache = new SumCache($model);
            $sumCache->apply(function ($config) use ($model, $sumCache) {
                $sumCache->updateCacheRecord($config, '+', $model->{$config['columnToSum']}, $model->{$config['foreignKey']});
            });
        });

        static::updated(function ($model) {
            (new SumCache($model))->update();
        });

        static::deleted(function ($model) {
            $sumCache = new SumCache($model);
            $sumCache->apply(function ($config) use ($model, $sumCache) {
                $sumCache->updateCacheRecord($config, '-', $model->{$config['columnToSum']}, $model->{$config['foreignKey']});
            });
        });
    }
public static function bootSummable()
    {
        static::created(function ($model) {
            $sumCache = new SumCache($model);
            $sumCache->apply(function ($config) use ($model, $sumCache) {
                $sumCache->updateCacheRecord($config, '+', $model->{$config['columnToSum']}, $model->{$config['foreignKey']});
            });
        });

        static::updated(function ($model) {
            (new SumCache($model))->update();
        });

        static::deleted(function ($model) {
            $sumCache = new SumCache($model);
            $sumCache->apply(function ($config) use ($model, $sumCache) {
                $sumCache->updateCacheRecord($config, '-', $model->{$config['columnToSum']}, $model->{$config['foreignKey']});
            });
        });
    }
public static function bootSummable ( ) { static :: created ( function ( $ model ) { $ sumCache = new SumCache ( $ model ) ; $ sumCache -> apply ( function ( $ config ) use ( $ model , $ sumCache ) { $ sumCache -> updateCacheRecord ( $ config , '+' , $ model -> { $ config [ 'columnToSum' ] } , $ model -> { $ config [ 'foreignKey' ] } ) ; } ) ; } ) ; static :: updated ( function ( $ model ) { ( new SumCache ( $ model ) ) -> update ( ) ; } ) ; static :: deleted ( function ( $ model ) { $ sumCache = new SumCache ( $ model ) ; $ sumCache -> apply ( function ( $ config ) use ( $ model , $ sumCache ) { $ sumCache -> updateCacheRecord ( $ config , '-' , $ model -> { $ config [ 'columnToSum' ] } , $ model -> { $ config [ 'foreignKey' ] } ) ; } ) ; } ) ; }
Boot the trait and its event bindings when a model is created.
Boot the trait and its event bindings when a model is created .