簡體   English   中英

WhereIn 內部 ->where() 數組 - Laravel 查詢生成器

[英]WhereIn Inside ->where() array - Laravel Query Builder

我正在嘗試在要傳遞給 Laravel 查詢生成器的 where 數組中使用 whereIn:


$where = [['Participants.Client_Id','IN', $clientId]];

DB::table('Participants')->where($where)->get()

類似的東西是我想要實現的,我知道有一些解決方法,比如使用 whereIn,但我在這里分享一小段代碼給你一個想法,所以我需要更改數組以使其工作一個 whereIn,不將 ->where 更改為 ->whereIn 或 ->whereRaw

  DB::table('participants)->whereIn('Participants.Client_Id',$clientId)->get();

您必須在$clientId變量中收集 ID。

如果我理解,你可以這樣做:

$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();

作為 laravel 文檔,您可以在where中使用數組,並且該數組的每個元素必須是具有三個值的數組。 所以你的$where變量是正確的。

但是正如我in運算符中搜索的那樣,where 的查詢構建器不支持。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM