有没有办法在 Laravel 中的单个连接中运行多个更新查询,
查询:
update users set score = score+130 where id = 12;
update users set score = score+10 where id = 10;
update users set score = score+10 where id = 14;
我尝试过:(不起作用)
DB::update("
update users set score = score+130 where id = 12;
update users set score = score+10 where id = 10;
update users set score = score+10 where id = 14;
");
谢谢
最佳答案
您的案例可以通过两个查询得到解决:
DB::table('users')->where('id', 12)->increment('score', 130);
DB::table('users')->whereIn('id', [10, 14])->increment('score', 10);
关于php - 拉拉维尔 4 : run multiple update query in 1 request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29351343/