In this post, i will tell you how to get last executed query in Laravel.
Sometime while working with laravel framework you need to see last executed query for debugging .
You can use
DB::getQueryLog() function to get all executed queries if you want to get last executed then use
Before getting query log you need to first enable it by using
DB::enableQueryLog() function and then you can get all executed queries.
- public function querylog()
- $list = \DB::table("categories")->get();
- $query = \DB::getQueryLog();
Array ( [query] => select * from `categories` [bindings] => Array ( ) [time] => 8.09 )
If there are multiple DB connections then you must specify it by following way :
First you will need to enable query log for your connection :
Now you can get log for that connection :