Stevebauman\Inventory\Traits\InventoryTransactionTrait::bootInventoryTransactionTrait PHP Method

bootInventoryTransactionTrait() public static method

Overrides the models boot function to generate a new transaction history record when it is created and updated.
public static bootInventoryTransactionTrait ( ) : void
return void
    public static function bootInventoryTransactionTrait()
    {
        static::creating(function (Model $model) {
            $model->setAttribute('user_id', Helper::getCurrentUserId());
            if (!$model->beforeState) {
                $model->beforeState = $model::STATE_OPENED;
            }
        });
        static::created(function (Model $model) {
            $model->postCreate();
        });
        static::updating(function (Model $model) {
            /*
             * Retrieve the original quantity before it was updated,
             * so we can create generate an update with it
             */
            $model->beforeState = $model->getOriginal('state');
            $model->beforeQuantity = $model->getOriginal('quantity');
        });
        static::updated(function (Model $model) {
            $model->postUpdate();
        });
    }