首页 > 解决方案 > Laravel Raw 查询转换为 Eloquent 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

今天进入 laravel 雄辩的 ORM2020-03-27日期。

我是这样写的,但是语法错误

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();

标签: phpmysqllaravel-5

解决方案


推荐阅读