alex
alex

Reputation: 7895

Laravel update statement issue

I'm trying to run this update statement:

\DB::update('UPDATE order_items SET set_id = ? WHERE id IN (?)',[$model->id, '2,3,4']);

it should update order_items with ids 2 and 3 and 4, but only order_item 2 is updated and two other ids is ignored .

Upvotes: 0

Views: 71

Answers (2)

Panagiotis Koursaris
Panagiotis Koursaris

Reputation: 4013

The correct laravel query builder is like bellow:

DB::table('order_items')->whereIn('id', [2, 3, 4])->update(['set_id' => $model->id]);

Upvotes: 0

linuxartisan
linuxartisan

Reputation: 2426

Try the Eloquent way

OrderItem::whereIn('id', [2,3,4])
         ->update(['set_id' => $model->id]);

Assuming you have a model for order_items as OrderItem.

Upvotes: 1

Related Questions