Laravel 使用 increment 和 decrement 會出現進度丟失的問題

由於歷史緣由,在Laravel 5.3版本 使用 Eloquentincrement 出現了精度丟失,this

重寫incrementOrDecrementAttributeValue方法,使用 bcadd 進行計算,保留2位小數。code

protected function incrementOrDecrementAttributeValue($column, $amount, $method)
    {
        $this->{$column} = bcadd($this->{$column}, ($method == 'increment' ? $amount : $amount * -1), 2);
        $this->syncOriginalAttribute($column);
    }
相關文章
相關標籤/搜索