我正在嘗試在要傳遞給 Laravel 查詢生成器的 where 陣列中使用 whereIn:
$where = [['Participants.Client_Id','IN', $clientId]];
DB::table('Participants')->where($where)->get()
類似的東西是我想要實作的,我知道有一些解決方法,比如使用 whereIn,但我在這里分享一小段代碼給你一個想法,所以我需要更改陣列以使其作業一個 whereIn,不將 ->where 更改為 ->whereIn 或 ->whereRaw
uj5u.com熱心網友回復:
DB::table('participants)->whereIn('Participants.Client_Id',$clientId)->get();
您必須收集$clientId變數中的 ID。
uj5u.com熱心網友回復:
如果我理解,你可以這樣做:
$wheres = [['Participants.Client_Id','IN', [$clientId]]];
$query = DB::table('Participants');
foreach($wheres as $where) {
$query->where($where[0], $where[1], $where[2]);
}
$participants = $query->get();
uj5u.com熱心網友回復:
作為 laravel 檔案,你可以使用陣列 inwhere并且這個陣列的每個元素必須是一個具有三個值的陣列。所以你的$where變數是正確的。
但是正如我搜索in的那樣,where 的查詢構建器不支持運算子。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/505796.html
標籤:php 拉拉维尔 laravel-5 雄辩 sqlbuilder
下一篇:PHP中沒有互聯網的CURL請求
