3

Based on the code below, I want to update all in customer to status 1 where status = 2. However, i want to run the code below where customer_id not in (1, 3, 5, 8).

$customerNotIn = array(1, 3, 5 ,8);
Customer::updateAll(['status' => 1], 'status = 2');

How can i achieve that?

CloudSeph
  • 863
  • 4
  • 15
  • 36

1 Answers1

7

The condition can be in the format of what you'd put in a ->where(), so in your case would be:

$customerNotIn = array(1, 3, 5 ,8);
Customer::updateAll(['status' => 1], ['AND', 
    'status = 2', 
    ['NOT IN', 'status', $customerNotIn]
]);
gmc
  • 3,910
  • 2
  • 31
  • 44
  • this is not correct. this will change to status 1 where not in 1,3,5,8. what i want is to change status to 2. but not in customer_id = 1,3,5,8 – CloudSeph Apr 14 '17 at 03:24
  • You mean you need both conditions? I don't understand. What the final status should be and under what condition(s)? – gmc Apr 14 '17 at 03:26
  • The use the `AND` operator to concat conditions, just as you would in a where block – gmc Apr 14 '17 at 03:31