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);
    }
相关文章
相关标签/搜索