How to get last executed mysql query in laravel ?

By Hardik Savani | January 11, 2016 | | 30011 Viewer | Category : Laravel MySql


If you are working on laravel framwork and you use query builder of laravel 5. but you want to get last executed mysql query from laravel. If you are working on laravel 5 then you have to first enable query log that way it can be store query log. At last getQueryLog() through you can get last executed query.

I give you example of how to get last executed mysql query. you can use example as following example.

public function querylog()

{

DB::enableQueryLog();

$item = Item::find(2);

$last_query = DB::getQueryLog();

print_r($last_query);

}

Try this.............



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
***Do you want me hire for your Project Work? Then Contact US.