Laravel how to get query with bindings?

前端 未结 14 712
小蘑菇
小蘑菇 2021-01-31 15:58

I have some query that I need to pass to another query using query builder

$query = DB::table(\'table\')->whereIn(\'some_field\', [1,2,30])->toSql();

Mode         


        
14条回答
  •  盖世英雄少女心
    2021-01-31 16:43

    You can do something like this:

    $escapedBindings = array();
    
    foreach($query->getBindings() as $item) {$escapedBindings[] = '"'.$item.'"';}
    
    $sql_with_bindings = Str::replaceArray('?', $escapedBindings, $query->toSql());
    

提交回复
热议问题