How to get last query log in Laravel 5.6?


Hi Developer,

In this article, i will let you know how to get last query log in laravel 5.6 application. we can simply get last mysql query log from model eloquent query. So if you need to see what you execute last mysql query then you need to follow this tutorial.

If you need to debug your last mysql query in laravel 5.6 then you can do it simply by following example. We know laravel provide their own query builder So sometime we write big query or something big logic on laravel query builder. But it's give us error and you didn't get it properly then you need to run manually sql query to your phpmyadmin.

So here i will give you many example to get your last query in laravel 5.6, So let's simple see bellow example how it works.

Debug 1:

$users = DB::table("users")->toSql();

dd($query);

Debug 2:

DB::enableQueryLog();

$user = DB::table("users")->get();

$query = DB::getQueryLog();

dd($query);

Debug 3:

DB::enableQueryLog();

$user = DB::table("users")->get();

$query = DB::getQueryLog();

$query = end($query);

dd($query);

I hope you found your best solution....






March 8, 2018 | Category : PHP Laravel Laravel 5 Laravel 5.6
Related Posts