2014-03-12 148 views
0

我有以下的,我想翻譯成Laravel的查詢生成器的詢問:Laravel ORM查詢生成器

SELECT t.name, t.description, u.first_name as assignee_fname, u.last_name as assignee_lname, 
us.first_name as reporter_fname, us.last_name as reporter_lname 
FROM `tasks` AS t 
LEFT JOIN `users` AS u 
ON (t.asignee_id = u.id) 
LEFT JOIN `users` AS us 
ON (t.reporter_id = us.id); 

你有什麼想法,我該怎麼辦呢?

謝謝

回答

0
DB::table('tasks')->select('tasks.name', 'users.first_name AS assignee_fname', ...) //and the rest of your column 
->leftJoin('users', 'taks.asignee_id', '=', 'users.id') 
->leftJoin('users', 'tasks.reporter_id', '=', 'users.id') 
+0

謝謝你的解決方案。我可以在問題中使用用戶表的別名嗎? 這很重要,因爲我必須從同一個表中獲取兩個不同人的信息。 – api

+0

是的,看到編輯後的解決方案 – har2vey

+0

工程就像一個魅力。非常感謝你。 – api