method one:
$sql = DB::table('my_table')->select()->tosql();
This method supports select statement
Method Two:
DB::connection()->enableQueryLog(); DB::table('my_table')->insert($data); $logs = DB::getQueryLog(); dd($logs);
This method supports select statement
Method three:
// add event listeners need to print before the SQL statement. :: the listen DB (function ($ Query) { $ Bindings = $ query-> Bindings; $ SQL = $ query-> SQL; foreach ($ Bindings the replace AS $) { ? $ Value = is_numeric (the replace $) $ the replace: " '" $ the replace.. "'"; $ SQL = preg_replace ( '? / \ /', $ value, $ SQL, 1); } dd ($ SQL); }); // SQL statement to be printed $ res = DB :: table ( 'my_table ') -> insert ($ data);
This method supports insert, update, delete, select and so on.
Reprinted articles https://learnku.com/articles/8654/how-does-laravel56-print-sql-summary-of-insertupdateselect-printing-method