I want to get the some data and also last leave date of the employee with their employee name so i wrote this query how can i do this in laravel 5
SELECT employee.firstname,employee.lastname,employee.id,hr_leave.*,LAST(hr_leave.date) AS lastleaveday
FROM employee
INNER JOIN hr_leave
ON employee.id=hr_leave.hrid
WHERE hr_leave.oid=$id
employee
id oid firstname lastname
id is primary key
hr_leave
id oid hrid leave_from leave_to days reason
id is primary key hrid is the foreign key
more info - https://laravel.com/docs/5.1/queries
Read this Article
You can use below example.
$users = \DB::select(“SELECT users.,products. FROM
users
LEFT JOINproducts
ON users.id
= products.user_id
WHERE 1 ORDER BY users.id
ASC”);