How to print last query in laravel?

Today, We want to share with you last query in laravel.In this post we will show you Query Helper Methods, hear for
Echo/Print Query Result
we will give you demo and example for implement.In this post, we will learn about using using DB::enableQueryLog() & enableQueryLog() execute a query with an example.

How to Get Last Executed Query in Laravel?

There are the Following The simple About laravel print last query Full Information With Example and source code.

As I will cover this Post with live Working example to develop echo last query Code Example, so the some major files and Directory structures for this example is following below.

Also Read:

Example : get current sql query using toSql()

$product = Product::where('id',1)->toSql();

print_r($product);

Example : using DB::getQueryLog()

DB::enableQueryLog();

$product = Product::get();

$query = DB::getQueryLog();

print_r($query);

Example: get exactly last query using end()

DB::enableQueryLog();

$product = Product::get();

$query = DB::getQueryLog();

$query = end($query);

print_r($query);

I hope you get an idea about print last query in laravel.
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.

Leave a Comment