本文介紹了具有多個(gè)條件的 Laravel Eloquent 內(nèi)連接的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我有一個(gè)關(guān)于具有多個(gè)值的內(nèi)部連接的問(wèn)題.我確實(shí)在 Laravel 中構(gòu)建了這樣的代碼.
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"));
});
}
唯一的問(wèn)題是,它給出了這個(gè)結(jié)果:
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 ( ))
如您所見(jiàn),join 中的多個(gè)條件沒(méi)有問(wèn)題,但它認(rèn)為 1
是一列而不是字符串.這是否可能,或者我必須在何處修復(fù)它.
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();
這篇關(guān)于具有多個(gè)條件的 Laravel Eloquent 內(nèi)連接的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!