Laravel 5.5 get last query log example


If you need to debug your last mysql query in laravel 5.5 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.5, 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....


September 8, 2017 | 2068 Viewer | Category : PHP Laravel

Related Posts: