Laravel Redirect To Another URL / Web Page - HTTP Laravel Redirects

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 Laravel: How to show (or log) all SQL queries executed by Laravel 6 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 source code.

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

  Laravel Tips Tricks and Techniques for Developers

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()

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

Example 3: laravel enable query log

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

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

Web Programming Tutorials Example with Demo

Read :

Summary

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.
I would like to have feedback on my infinityknow.com 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.

  Laravel Insert Update Delete Multiple checkbox value Example