Search
 
SCRIPT & CODE EXAMPLE
 

SQL

convert sql query to laravel eloquent

//Ref: https://jjlabajo.github.io/SQLtoEloquent/

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)

After Convert:
DB::table("employees as emp")
->leftJoin("attendance_log as al", function($join){
	$join->on("emp.device_emp_id", "=", "al.emp_id");
})
->join("departments as dep", function($join){
	$join->on("emp.department_id", "=", "dep.id");
})
->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'")
->whereIn("al.emp_id", "$emp_id")
->groupBy("emp")
->get();     
             
Comment

PREVIOUS NEXT
Code Example
Sql :: how to open database 
Sql :: sql check if a record exists 
Sql :: sql joining 3 tables 
Sql :: postgres select from values 
Sql :: change order of sql columns 
Sql :: sql script to delete duplicate records in a table 
Sql :: get month and year from date in mysql sequelize 
Sql :: add 10 to all numbers in a column sql 
Sql :: how to format tables in sqlplus 
Sql :: how to select the lowest values from table per client sql 
Sql :: select all domains of database firbird 
Csharp :: create a directory if it doesnt exist c# 
Csharp :: unity set mouse cursor lock 
Csharp :: split on uppercase c# 
Csharp :: regions unity 
Csharp :: draw sphere gizmo unity 
Csharp :: asp.net core multiple get methods 
Csharp :: change sprite of gameobject unity 
Csharp :: read in multiple numbers c# 
Csharp :: unix time c# 
Csharp :: how get url in laravel 
Csharp :: c# how to simulate mouse click 
Csharp :: initialise icollection c# 
Csharp :: unity get speed of object 
Csharp :: unity 2d detect click on sprite 
Csharp :: c# loop through array 
Csharp :: Schema::defultString larvel 
Csharp :: unity destroy object when out of screen 
Csharp :: move towards target unity 
Csharp :: unity array to list 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =