Lets say I have a table like this,
|id|area_id|area_values|
|1 |12 |value 1 |
|2 |12 |value 2 |
|3 |12 |value 3 |
|4 |01 |value 4 |
and I would like to update only those that have an area of 12. My new values is an array $values = ['newvalue1,'newvalue2',newvalue3']
;
I have tried using array_map like this.
$ids = Area::where('area_id', 12)->pluck('id')->toArray();
array_map(function ($id) {
array_map(function($areaValue){
Area::find($id)->update(['area_values' => $areaValue]);
}, $values);
}, $ids)
But the problem I encountered was it's being updated with only the first value of the new array, which is newValue1
What is the best approach on doing that?