Hello Laravel Developers, Good day. Please how can I convert a raw sql query to laravel query builder or eloquent ORM. I want to generate attendance report and display the report using data table. I want to show every employees data with his/her daily attendance log. I have two table employees and attendance_log where attendance_log belongs to emp_id from employees table.
My problem is:
I can't write this query in laravel query builder or eloquent ORM.
How to filter or search data from data table?
$emp_id = $request->input('emp_id'); $start_date = $request->start_date; $end_date = $request->end_date; $data = DB::select(" SELECT emp.*, dep.department_name, al.emp_id, al.auth_date, min(al.auth_time) as 'check_in', max(al.auth_time) as 'check_out' FROM employees as emp LEFT JOIN attendance_log as al ON emp.device_emp_id = al.emp_id JOIN departments as dep ON emp.department_id = dep.id WHERE al.emp_id IN $emp_id // $emp_id is an array of employee's ID WHERE date(al.auth_date) BETWEEN $start_date AND $end_date GROUP BY emp.device_emp_id, date(al.auth_date_time) ");
