简体   繁体   English

Laravel WhereIn 方法在 Eloquent 不起作用

[英]Laravel WhereIn method in Eloquent not working

I want to use the WhereIn method in Eloquent but it now works like the below function.我想在 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();
?>

But In the query, it's displaying like this.但在查询中,它是这样显示的。

select * from `decoration` where `deco_print_type` in ('\'100109C9\',\'100110B9\',\'100144C9\',\'100186C9\'');

I can't understand why these slashes are coming.我不明白为什么会出现这些斜线。 Please help me to fix this issue.请帮我解决这个问题。

The whereIn() method will accept an array of all the items. whereIn()方法将接受所有项目的数组。 In your example you are passing an array with one element with all the values already concatenated.在您的示例中,您正在传递一个包含一个元素的数组,其中所有值都已连接。 Based on your example you only need to pass $decArr根据您的示例,您只需要通过$decArr

DB::table('decoration')->whereIn('deco_print_type', $decArr)->get();

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

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