HDTuto.com

Laravel 5.7 - get all eloquent query log example


Hey Guys,

Here, we will learn how to get last query log in laravel 5.7. if you are a laravel developer then we know we always need to print last sql query log and need to debug queries where is a issue?.

So, in this post i am going to give you three way to capture last query log and print in laravel 5.7 application. So, you can simply use any one for debug your application.

Example 1:

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

dd($query);

Example 2:

DB::enableQueryLog();

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

$query = DB::getQueryLog();

dd($query);

Example 3:

DB::enableQueryLog();

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

$query = DB::getQueryLog();

$query = end($query);

dd($query);

I hope you found your best solution....




October 17, 2018 | Category : PHP Laravel Laravel 5 Laravel 5.7
Related Posts