How to Get Last Executed Query in Laravel 8

In this tutorial you will learn about the How to Get Last Executed Query in Laravel 8 and its application with practical example.

In this How to Get Last Executed Query in Laravel 8 tutorial I will show you how to get or print last executed query in laravel application. In this tutorial you will learn to display or print last executed query in your laravel 8 application. In this article I will share various example to display or print last executed sql query in laravel. In this examples we will be using toSql(), DB::enableQueryLog() and DB::getQueryLog() to output of print sql query. These examples we will help us to debug last executed sql query in laravel.

How to Get Last Executed Query in Laravel 8

In this step by step tutorial I will demonstrate you with example to print or output last executed query in laravel application. We will use sql query in laravel 8 using toSql(), DB::enableQueryLog() and DB::getQueryLog(). Please follow the instruction given below:

Example 1:-

Please put the following code in your controller code:

Output:-

Example 2:-

Please put the following code in your controller code:

Output:-

Example 3:-

Please put the following code in your controller code:

Output:-

In this tutorial we have learn about the How to Get Last Executed Query in Laravel 8 and its application with practical example. I hope you will like this tutorial.