0👍
✅
Just move your update query inside the foreach loop:
foreach($data['data'] as $x => $emp_key) {
DB::table('employee')->where('emp_key', $emp_key)->update([
'group_code' => $id,
]);
}
What your previous code was doing was that the $emp_key
variable was only storing the last value in your loop thus it was the only one being updated by your query
Source:stackexchange.com