Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write Custom query in laravel 5

Tags:

php

laravel-5

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
like image 767
sasy Avatar asked Feb 15 '16 05:02

sasy


2 Answers

For Select --> DB::select('your query here.....');
For Insert --> DB::insert('your query here.....');
For Update --> DB::update('your query here.....');
For Delete --> DB::delete('your query here.....');
For General -->  DB::statement( 'your query here....' );

Read this Article

like image 194
Shailesh Katarmal Avatar answered Sep 17 '22 18:09

Shailesh Katarmal


$empls= DB::table('employee')
            ->join('hr_leave', 'hr_leave.hrid', '=', 'employee.id')
            ->select('employee.*')
            ->where('hr_leave.oid', $id)
            ->get();

more info - https://laravel.com/docs/5.1/queries

like image 43
Mazba Kamal Avatar answered Sep 17 '22 18:09

Mazba Kamal