Laravel how to get query with bindings?

前端 未结 14 713
小蘑菇
小蘑菇 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:46

    $sqlQuery = Str::replaceArray(
        '?',
        collect($query->getBindings())
            ->map(function ($i) {
                if (is_object($i)) {
                    $i = (string)$i;
                }
                return (is_string($i)) ? "'$i'" : $i;
            })->all(),
        $query->toSql());
    

提交回复
热议问题