I want to update multiple records with different values for each record. What should I do with the laravel eloquent? Here's my code example. Thanks in advance.
$employee_presences = Employee_presence::
where('employee_id', $report_history->employee_id)
->whereBetween('presence_date',[$report_history->report->start_period,$report_history->report->end_period])
->get();
foreach ($presences_data as $presence_data)
{
foreach ($employee_presences as $employee_presence)
{
$updated_presences = Employee_presence::
where('id', $employee_presence->id)->update([
'presence_value' => $presence_data['presence_value']
]);
}
}
These are the values inside $presences_data. This is the new data for updating the records.
These are the records $employee_presences: