I have this weird problem, where I'm trying to update an entry into my SQL database and it keeps adding 1 when I increase the value of the column and save it.
For example, I += 1
to the existing value of an entry of 2, the result is 3, but when saved it is logged as 4 in the database... The column structure is int(20) unsigned.
PHP:
$quantity = 1;
$item = \App\item::find($item_id);
$item->items_sold += $quantity;
$item->save();
if I dd($item->items_sold)
the result is correct, and the value is changed by the specified amount. However when I check the database, the value is increased by the specified amount and then increased again by 1...
Any help would be very much appreciated! Thankyou :)
查询生成器还提供了增加或减少给定列的值简便的方法见
\App\item::find($item_id)->increment('items_sold',1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.