Debugge eloquent queries in laravel

1

I make transactions with eloquent de laravel 5.5 and I would like to debug the real query for example:

objeto::all();

and I would like to see the real query for example

select * from objeto

in the same way for insert and update

    
asked by Pablo Moraga 08.05.2018 в 16:55
source

1 answer

1

To know which queries are executed and which are in SQL format, you could use the fascade DB in the following way in the file routes/web.php (before all defined routes)

DB::listen(function($query){
  //Imprimimos la consulta ejecutada
  echo "<pre> {$query->sql } </pre>";
});

Route::get(...
/* Más rutas */

This is specified in the Laravel documentation where you also have the option to place the Listen in AppServiceProvider .

    
answered by 08.05.2018 в 17:01