Laravel how to get query with bindings?

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

    If you want to get an executed query including bindings from the query log:

    \DB::enableQueryLog();
    \DB::table('table')->get();
    dd(str_replace_array('?', \DB::getQueryLog()[0]['bindings'], 
          \DB::getQueryLog()[0]['query']));
    

提交回复
热议问题