Home > OS >  Laravel - update data from array
Laravel - update data from array

Time:04-18

I want update an array of ids.

enter image description here

Eloquent Query

$my_ids = json_encode($request->post('my_ids'));
Lead::whereIn('id', $my_ids)->update(['op' => 2]); 

but I need to pass a string with comma.

enter image description here

How can I solve it?

CodePudding user response:

I believe the ids you receive from post request is object string so you need to decode that string in order to get an array.

$my_ids = json_decode($request->post('my_ids'), true);
Lead::whereIn('id', $my_ids)->update(['op' => 2]); 
  • Related