Laravel 6 Print Last Query(Debugging Queries)

Today, We want to share with you Laravel 6 Print Last Query(Debugging Queries).In this post we will show you Laravel 6 Eloquent display query log, hear for Laravel 6 print last executed sql query with Query log we will give you demo and example for implement.In this post, we will learn about query in laravel model Laravel: How to show (or log) all SQL queries executed by Laravel 6 laravel eloquent get last query with an example.

Laravel 6 Print Last Query(Debugging Queries)

There are the Following The simple About How to get last executed query in Larave 6? Full Information With Example and laravel query builder last insert id source code.

As I will cover this Post with live Working example to develop laravel enable query log with print query in laravel 5.5, so the print last executed query in laravel 6 is used for this example is following below.

Example 1: laravel 6 enable query log

laravel 6 db query log

DB::enableQueryLog();// simple enable query first

    // Your MySQL queries goes here
    // ...

    // And then display/print Queries executed....
    $sql_queries = DB::getQueryLog();
    foreach($sql_queries as $key=>$query)
        Log::debug(" $key Query - " . json_encode($query));

Example 2: laravel 6.0 get last query

get exactly last query using end()

$product = Product::get();
$q_query = DB::getQueryLog();
$q_query = end($q_query);

Example 3: laravel enable query log

using DB::enableQueryLog() of Laravel Query builder. enableQueryLog()

laravel 5 query builder insert last id

$product = Product::get();
$q_query = DB::getQueryLog();

Web Programming Tutorials Example with Demo

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel 5.8, 6.0 & 6.2 query builder with laravel 5 query builder insert get last id.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1.   Simple jQuery Fade Effects Example
  2.   jQuery AJAX laravel 6 Delete Data from database
  3.   Laravel 6 Count from Join Example
  4.   how to get last inserted record in laravel?
  6.   Laravel 5/6/7 Import & Export data to Excel CSV using maatwebsite
  7.   Codeigniter Session set and Retrieve multidimensional array
  8.   Custom Fancy Custom Scrollbar styling using CSS and Jquery
  9.   Vue JS - Get Query String Value Example
  10.   how to upload image in ckeditor in Laravel?