我有一些問題,我的雄辯模型,我嘗試在一箇中加入兩個不同的表格Laravel LeftJoin
現在我有兩個表。
一臺名爲 「company_saved_cv」
|id|company_id|worker_id |
--------------------------
|1| 2 | 61 |
|3| 3 | 66 |
|4| 2 | 69 |
--------------------------
二表名 「工人」
|id|location|name_and_surname|
------------------------------
|61|London | John John |
|62|London | John John |
|66|London | John John |
|67|London | John John |
|68|London | John john |
我whana得到表是這樣的。
|id|location|name_and_surname|worker_id|
---------------------------------------|
|61|London | John John | 61 |
|62|London | John John | NULL |
|66|London | John John | 66 |
|67|London | John John | NULL |
|68|London | John john | NULL |
哪裏是我的模型功能
public static function CvSearch($interested_field, $location)
{
$match = "MATCH(`interested_fields`) AGAINST (?)";
$query = Worker::select('workers.name_and_surname', 'workers.id', 'workers.location','company_saved_cv.worker_id')
->leftJoin('company_saved_cv', function($leftJoin)
{
$leftJoin->on('company_saved_cv.worker_id', '=', 'workers.id')
->where('company_saved_cv.company_id', '=', Session::get('company_id'));
})
->where('workers.location', '=', $location)
->whereRaw($match, array($interested_field))
->orderBy('workers.created_at')
->paginate(10);
return $query;
}
如果我評論這一行:->where('company_saved_cv.company_id', '=', Session::get('company_id'));
這是工作,但我需要從表中的工人只能得到行,其中的company_id = 2(在我的例子);
Session::get('company_id') = 2
我將通過將其記錄在laravel.log文件中來檢查它。
我fink它是哪裏('company_saved_cv.company_id','=',Session :: get('company_id'))的問題;請求,但我無法弄清楚,也許有人可以幫助我?
你的邏輯是什麼來實現結果。因爲我無法看到任何形式的關係b/w你的表。 – 2014-11-03 09:59:15