Laravel Eloquent 中的 WhereIn 方法无效

Laravel WhereIn method in Eloquent not working

我想在 Eloquent 中使用 WhereIn 方法,但它现在像下面的函数一样工作。

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