drogon982007 2018-04-08 14:30
浏览 350
已采纳

在laravel中一次更新多个列值

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');       
}
  • 写回答

1条回答 默认 最新

  • duandian8110 2018-04-08 14:40
    关注

    Use this:

    whereIn('employee_id', $employeeIds)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?