我正在尝试使用结帐时间更新所有选定雇员的出勤列outtime
。在intime
登记时间期间已成功存储在数据库中,但是更新遇到了麻烦。我做了下面的事情,但是它只更新第一行。请问有人会帮助我写些什么?
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');
}
最佳答案
用这个:
whereIn('employee_id', $employeeIds)