Generate The Raw MySQL Query From Laravel Query Builder

后端 未结 14 1441
醉话见心
醉话见心 2021-02-02 12:04

How can i get mysql query of a laravel query

Convert:

App\\User::where(\'balance\',\'>\',0)->where(...)-         


        
14条回答
  •  情书的邮戳
    2021-02-02 12:48

    use toSql() method of laravel to get the query to be executed like

    App\User::where('balance','>',0)->where(...)->toSql();
    

    But Laravel will not show you parameters in your query, because they are bound after preparation of the query. To get the bind parameters, use this

    $query=App\User::where('balance','>',0)->where(...);
    print_r($query->getBindings() );
    

    enable the query log as DB::enableQueryLog() and then output to the screen the last queries ran you can use this,

    dd(DB::getQueryLog());
    

提交回复
热议问题