UPDATE goods SET qty++ WHERE id = '4'
这是我的controller
代码
public function store(Request $request)
{
$g = new goods();
$g->qty = ++;
$g->save();
}
答案 0 :(得分:1)
这是解决方案
$post = Goods::find(3);
$post->qty = $post->qty + 1;
$post->save();
您可以找到该记录并以+1更新。
答案 1 :(得分:1)
查看文档:{{3}}
例如:DB::table('users')->increment('votes', 5);
答案 2 :(得分:0)
你可以试试这个吗?
public function store(Request $request) {
$g = goods::find(4);
$g->qty += 1;
$g->save;
}
答案 3 :(得分:0)
您不能无所事事地呼叫++
,而这样做(如果可行的话)只会加1。
为什么不只说$g->qty = 1;
?
如果您在qty
中已经有了一些值,请先调用$g->qty++;
,然后再调用->save();
(注意“()”)。