简体   繁体   English

Laravel WhereNotIn只有一个数字

[英]Laravel WhereNotIn only one number

Here is code: 这是代码:

$all = "32,34,24,28,31";
 $show_app = DB::table('apartments')
->whereNotIn('id', [$all])
->get();

I don't know why variable $all not working. 我不知道为什么变量$ all不起作用。 When is listed only hide first apartment "32". 列出时仅隐藏第一个公寓“ 32”。 Rest apartment list anyway. 其余的公寓清单。 But if i copy all numbers in whereNotIn then is working??? 但是,如果我将所有数字都复制到whereNotIn中,则可以正常工作??? I need this variable @all! 我需要这个变量@all! I have all variable in my table. 我的桌子上都有所有变量。 I try with ->toSql() and show only one "?" 我尝试使用->toSql()并仅显示一个"?" instead of five "?, ?, ?, ?, ?" 而不是五个"?, ?, ?, ?, ?"

I am not a laravel user, but in your all variable, why not directly assign the array instead of saving as string? 我不是laravel用户,但是在您的all变量中,为什么不直接分配数组而不是另存为字符串?

Example: Instead of: 示例:而不是:

$all = "32,34,24,28,31";

why not? 为什么不?

$all = [32,34,24,28,31]; 

Then use the $all variable like this:. 然后使用$ all变量,如下所示:

 $show_app =    DB::table('apartments') ->whereNotIn('id', $all) ->get();

i found my problem: I must use explode 我发现了我的问题:我必须使用explode

$result="";
foreach($prikaz_bookinga as $prikaz_booking) :  
$result.=$prikaz_booking->id.','; 
endforeach ;
$all=rtrim($result, ',');

Then in query add this. 然后在查询中添加它。

 ->whereNotIn('id', explode(',', $all))

Now i go to drink beer. 现在我去喝啤酒。 Work on this 8 days. 在这8天中工作。

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

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