[英]Laravel WhereIn method in Eloquent not working
我想在 Eloquent 中使用 WhereIn 方法,但它现在像下面的 function 一样工作。
<?php
$product = DB::table('product')
->join('supplier','supp_code','=','prod_supplier_code')
->select('product.*','supplier.supp_margin')
->where('prod_seo_title','=',$id)
->first();
$decArr = explode(',',$product->prod_decoration_type);
for($i=0; $i<count($decArr); $i++)
{
if($i==0)
$inString = "'".$decArr[$i]."','";
elseif ($i<(count($decArr))-1)
$inString .= $decArr[$i]."','";
else
$inString .= $decArr[$i]."'";
}
$proDeco = DB::table('decoration')->whereIn('deco_print_type', [$inString])->get();
?>
但在查询中,它是这样显示的。
select * from `decoration` where `deco_print_type` in ('\'100109C9\',\'100110B9\',\'100144C9\',\'100186C9\'');
我不明白为什么会出现这些斜线。 请帮我解决这个问题。
whereIn()
方法将接受所有项目的数组。 在您的示例中,您正在传递一个包含一个元素的数组,其中所有值都已连接。 根据您的示例,您只需要通过$decArr
DB::table('decoration')->whereIn('deco_print_type', $decArr)->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.