Online Snippets Library

Echo Last Executed Query In Laravel 5

To See last Executed query in Laravel 5 we need to enable query log of laravel.To Enable query log use "DB::enableQueryLog()" function before query. As we know DB::getQueryLog() function of laravel return all executed queries.To get last query we will use end() function which return last executed query.

$query = DB::getQueryLog();
$lastQuery = end($query);


Here is simple example.

$users= DB::select('select * from user where 1');
$query = DB::getQueryLog();
$lastQuery = end($query);


Array ( [query] => select * from user where 1 [bindings] => Array ( ) [time] => 0.39 )