Laravel Raw查询转换为雄辩的ORM格式

 收藏

谁能帮我转换此查询

SELECT 
   employees.username, 
   employees_attendance.employees_id, 
   SUM(employees_attendance.worked_hours) 
FROM 
   employees_attendance 
LEFT JOIN 
   employees ON 
   employees_attendance.employees_id=employees.id 
WHERE 
   timein LIKE '2020-03-26 %' 
GROUP BY 
   employees_attendance.employees_id

into laravel eloquent ORM 2020-03-27 today date.

我这样写,但是语法违反错误

DB::table('employees_attendance')
          ->leftJoin('employees', 'employees_attendance.employees_id', '=', 'employees.id')
          ->where('employees_attendance.employees_id', '=', 'employees.id')
          ->whereDate('timein', Carbon::today())
          ->select('employees.id as emp_id','employees.username as name')
          ->groupBy('employees_attendance.employees_id')
          ->get();
回复