Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to solve the problem of schedule loss when Laravel uses increment and decrement

Shulou Source: shulou.com Published: 2022-06-02 10:03:52 11月14日 Update

This article mainly introduces "how to solve the loss of progress in the use of increment and decrement in Laravel". In the daily operation, I believe that many people have doubts about how to solve the problem of progress loss in the use of increment and decrement in Laravel. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "how to solve the loss of progress in the use of increment and decrement in Laravel". Next, please follow the editor to study!

Due to historical reasons, increment that uses Eloquent in Laravel version 5.3 has lost precision.

Override the incrementOrDecrementAttributeValue method, using bcadd for calculation, leaving 2 decimal places.

Protected function incrementOrDecrementAttributeValue ($column, $amount, $method) {$this- > {$column} = bcadd ($this- > {$column}, ($method = = 'increment'? $amount: $amount *-1), 2); $this- > syncOriginalAttribute ($column);}

Note: increment does not recommend calculating floating point numbers

At this point, the study on "how to solve the loss of progress in the use of increment and decrement in Laravel" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Progress learning methods more help practical next history reasons decimals suggestions articles points versions theory knowledge articles precision websites materials Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei macOS vpn NVidia Linux