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();
});
}