Laravel show the last sql query

Posted: September 28, 2016 in Laravel, Uncategorized
Tags: ,

Hi, here are the simple steps to show the last sql query in Laravel 5.1:

#enable the query log
DB::enableQueryLog();

#your sql query execution
$query = DB::table('table_name');
$query->where('table_name.project_id', 15);
$res = $query->count();
 
#get your last query 
$query = DB::getQueryLog();
$lastQuery = end($query);

#dump sql
dd($lastQuery);

Credit: http://www.goodbytes.be/article/log-last-executed-eloquent-query-as-plain-sql-in-laravel-5

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s