简体   繁体   English

Laravel whereIn不返回结果

[英]Laravel whereIn does not return result

I'm trying to check whether an id is in a column or not and return true or false depending on that.我正在尝试检查 id 是否在列中,并根据它返回 true 或 false。 The problem is, the result keeps returning false even though the id is in the array.问题是,即使 id 在数组中,结果仍然返回 false。

The value for column other_users looks like this ["13","14"] : other_users列的值如下所示["13","14"]

$user = User::where('id',auth()->user()->id)->first(); // id = 13
$consultation = Consultation::whereIn('other_users',array($user->id))->first();
if($consultation)
    $result = true;
else
    $result = false;
}

dd($result); //always return false

The whereIn() function will not work in this case since the target is varchar (string) you may need to use 'like' in the query, something like: whereIn() function 在这种情况下将不起作用,因为目标是 varchar(字符串),您可能需要在查询中使用“like”,例如:

$consultation = Consultation::where('other_users', 'like', '%"'.$user->id.'"%')->first();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM