laravelBatch icon indicating copy to clipboard operation
laravelBatch copied to clipboard

Add new where condition???

Open hhuseyn opened this issue 3 years ago • 6 comments

Hi. How to?? $product_model = new Product; $index = 'id'; $value = [ ['id' => 1,'count' => 5], ['id' => 2,'count' => 3], ];

Batch::update($product_model , $value, $index); i want add new condition in Product model. Product where only show_index = 1(products table column) Batch::update($product_model , $value, $index); Please help me

hhuseyn avatar Jan 06 '21 10:01 hhuseyn

batch update only one condition.

$product_model = new Product;

$index = 'show_index';

$value = [
 ['show_index' => 1,'count' => 5],
 ['show_index' => 2,'count' => 3],
];

Batch::update($product_model , $value, $index);

mavinoo avatar Jan 06 '21 13:01 mavinoo

I think he meant multiple where condition, that's what I wanted to ask anyway. Like for example I have a settings table with user_id, key, and value columns. I'd like to use user_id and key as the condition to update value column

Zzombiee2361 avatar Feb 25 '21 04:02 Zzombiee2361

Try Batch::updateWithTwoIndex($model, $data, $index, $index2)

WalterWoshid avatar Mar 06 '21 11:03 WalterWoshid

Whoa, why isn't this documented in the readme

Zzombiee2361 avatar Mar 06 '21 16:03 Zzombiee2361

@Zzombiee2361 does it work? If it does, I'll add it to the readme

WalterWoshid avatar Mar 07 '21 01:03 WalterWoshid

Try Batch::updateWithTwoIndex($model, $data, $index, $index2)

It's working for me. But it's working for update only, if record does not exist then not creating new one

sandeep0108 avatar Aug 25 '23 11:08 sandeep0108