gpt4 book ai didi

laravel 5,具有多个值的 where 子句

转载 作者:行者123 更新时间:2023-12-01 07:46:32 24 4
gpt4 key购买 nike

我想将所有 $id 值传递给下面代码的第 3 行 where 子句。但当我试图返回 $friend 时,它是空的。我是否错误地处理了 $id 值?还是我在查询中弄错了?我检查了我的数据库,它应该返回 2 行。

我还通过返回它来检查 $id 并且它返回我期望的内容,我想我在 $friend 行的查询中弄错了。

$x = user->id;  

$id = DB::table('requests')->select('id')->where('id', '=', $x)->get();

$friend = DB::table('users')->where('id', 'in', $id)->get();

最佳答案

您需要使用 whereIn() ,也许整个交易的更好选择是:

$ids = DB::table('requests')->where('id', $x)->lists('id');
$friend = DB::table('users')->whereIn('id', $ids)->get();

注意 whereIn() 的第二个参数需要是一个数组。

关于laravel 5,具有多个值的 where 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32997432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com