Reputation: 4166
is there any way to run multiple update queries in single connection in Laravel,
queries:
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;
I tried: (not working)
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;
");
thanks,
Upvotes: 0
Views: 341
Reputation: 54379
Your case can be resolved with two queries:
DB::table('users')->where('id', 12)->increment('score', 130);
DB::table('users')->whereIn('id', [10, 14])->increment('score', 10);
Upvotes: 1