本文介紹了具有多個條件的 Laravel Eloquent 內連接的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個關于具有多個值的內部連接的問題.我確實在 Laravel 中構建了這樣的代碼.
I have a question about inner joins with multiple on values. I did build my code like this in laravel.
public function scopeShops($query) {
return $query->join('kg_shops', function($join)
{
$join->on('kg_shops.id', '=', 'kg_feeds.shop_id');
// $join->on('kg_shops.active', '=', "1"); // WRONG
// EDITED ON 28-04-2014
$join->on('kg_shops.active', '=', DB::raw("1"));
});
}
唯一的問題是,它給出了這個結果:
Only problem is, it gives this outcome:
Column not found: 1054 Unknown column '1' in 'on clause' (SQL: select `kg_feeds`.* from `kg_feeds` inner join `kg_shops` on `kg_shops`.`id` = `kg_
feeds`.`shop_id` and `kg_shops`.`active` = `1`) (Bindings: array ( ))
如您所見,join 中的多個條件沒有問題,但它認為 1
是一列而不是字符串.這是否可能,或者我必須在何處修復它.
As you can see, the multiple conditions in the join go fine, but it thinks the 1
is a column instead of a string. Is this even possible, or do I have to fix it in the where.
提前致謝!
推薦答案
return $query->join('kg_shops', function($join)
{
$join->on('kg_shops.id', '=', 'kg_feeds.shop_id');
})
->select('required column names')
->where('kg_shops.active', 1)
->get();
這篇關于具有多個條件的 Laravel Eloquent 內連接的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!