Laravel 4:在1个请求中运行多个更新查询

时间:2015-03-30 16:24:43

标签: php mysql laravel

有没有办法在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;
");

感谢,

1 个答案:

答案 0 :(得分:1)

您的案例可以通过两个查询解决:

DB::table('users')->where('id', 12)->increment('score', 130);
DB::table('users')->whereIn('id', [10, 14])->increment('score', 10);