Stevebauman\Inventory\Traits\InventoryStockTrait::bootInventoryStockTrait PHP Метод

bootInventoryStockTrait() публичный статический Метод

Overrides the models boot function to set the user ID automatically to every new record.
public static bootInventoryStockTrait ( )
    public static function bootInventoryStockTrait()
    {
        static::creating(function (Model $model) {
            $model->setAttribute('user_id', Helper::getCurrentUserId());
            // Check if a reason has been set, if not let's
            // retrieve the default first entry reason.
            if (!$model->reason) {
                $model->reason = Lang::get('inventory::reasons.first_record');
            }
        });
        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->beforeQuantity = $model->getOriginal('quantity');
            // Check if a reason has been set, if not let's
            // retrieve the default change reason.
            if (!$model->reason) {
                $model->reason = Lang::get('inventory::reasons.change');
            }
        });
        static::updated(function (Model $model) {
            $model->postUpdate();
        });
    }