1
我有一個本地Php/Mysql查詢,我需要轉換爲Laravel查詢。我在laravel的世界裏很新,發現它很有趣,但我在這個問題上已經超過3天了。Laravel聯盟與加入選項
這裏是我的家鄉PHP /思想報查詢
$sql = "SELECT a.employeeID, a.nric, a.fullName, b.salary, c.total_allowance, c.year, c.month, c.period, d.deptName, c.aws, c.additionals,
c.id, a.date_of_birth, c.total_additional
from employees a
LEFT OUTER JOIN salary b ON a.employeeID = b.employeeID
LEFT OUTER JOIN payrolls c ON a.employeeID = c.employeeID and year = '$presyear' and month = '$presmonth' and period = '$period'
LEFT OUTER JOIN department d ON a.designation = d.id
UNION
SELECT a.employeeID, a.nric, a.fullName, b.salary, c.total_allowance, c.year, c.month, c.period, d.deptName, c.aws, c.additionals,
c.id, a.date_of_birth, c.total_additional
from employees a
LEFT OUTER JOIN salary b ON a.employeeID = b.employeeID
LEFT OUTER JOIN payrolls c ON a.employeeID = c.employeeID and year != '' and month != '' and period != ''
LEFT OUTER JOIN department d ON a.designation = d.id
WHERE c.net_salary != ''";
它給我我想要的結果,但我不知道你們也許你想在這一個一些調整。
現在,這是因爲據我可以在Lravel
$result = Payroll::select('payrolls.id','payrolls.employeeID','fullName','month','year','period','department.deptName','payrolls.aws',
'payrolls.adjustment','payrolls.allowances','payrolls.alencashment','payrolls.housing_allowance',
'payrolls.med_reimburse','payrolls.overtime_hours','payrolls.overtime_pay','payrolls.reimbursement','payrolls.tips',
'net_salary','payrolls.total_additional','payrolls.total_allowance','payrolls.total_deduction','payrolls.total_cpf')
->join('employees', 'payrolls.employeeID', '=', 'employees.employeeID','left')
->join('department', 'employees.designation', '=', 'department.id','left')
->where('payrolls.year','=',$presyear)
->where('payrolls.month','=',$presmonth)
->where('payrolls.period','=',$period);
讓我不知道究竟是如何做到的工會和所有與外內加入如我在本地一樣。
我正在使用Laravel 4.2.17
謝謝。
任何人請。呵呵呵。 –