Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 SQL log / console

Is there something similar in Laravel that allows you to see the actual SQL being executed? In Rails, for example, you can see the SQL in console. In Django you have a toolbar.

Is there something like that in Laravel 4?

To clarify: My question is how to do it without code. Is there something that is built-in in Laravel that does not require me to write code in app?

UPDATE: Preferably I'd like to see CLI queries as well (for example php artisan migrate)

like image 289
Slava V Avatar asked Jun 27 '13 09:06

Slava V


Video Answer


2 Answers

If you are using Laravel 4, use this:

$queries    = DB::getQueryLog();
$last_query = end($queries);
like image 133
Maeh Avatar answered Oct 22 '22 18:10

Maeh


I do this in Laravel 4.

Just set it once in app/start/global.php or anywhere but make sure it is loaded and then it will start logging all your SQL queries.

Event::listen("illuminate.query", function($query, $bindings, $time, $name){
    \Log::sql($query."\n");
    \Log::sql(json_encode($bindings)."\n");
});
like image 31
Ashit Vora Avatar answered Oct 22 '22 18:10

Ashit Vora