I am trying to update attendance column outtime
of all selected employees with checkout time.During intime
check-in time successfully stored in the database, but I am getting trouble with the update. I did something like below, but it's updating the only first row. What should be written query would someone help me, please?
AttendanceController.php
public function checkout(Request $request)
{
$request->validate([
'outtime' => 'required',
'employee_id' => 'required',
]);
$outTime = Carbon::parse($request->outtime)->format('H:i:s');
$date = date('Y-m-d');
$employeeIds = $request->employee_id;
$data = [];
foreach ($employeeIds as $employeeId) {
$data[] = [
'employee_id' => $employeeId,
'attendance_date' => $date,
];
}
$update = Attendance::where('employee_id', $data)
->where('attendance_date', $date)
->update([
'outtime' => $outTime
]);
return back()->with('success', 'Checked Out');
}