Print last executed query in laravel
Created at 14-Mar-2021 ,
By samar
Print last executed query in laravel
In this session, we’ll try our hand at solving the "Print last executed query in laravel" puzzle by using the computer language.
-
--PATH app\Http\Controllers\<YourController.php>
DB::enableQueryLog(); //Change models name as per your requirement and do not forget use model in your controller file $employee = Employee::all(); $employeeDetail = EmployeeDetail::all(); $queries = DB::getQueryLog(); //Get the last query $last_query = end($queries); dd($last_query);
This code snippet will print last executed query in laravel in the form of raw SQL. There are two queries executed on Employee and EmployeeDetail models. But it will only show the query details (raw SQL query) of the EmployeeDetail model which is executed after the Employee model in our case.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- Get duplicate records in laravel
- How to create static page in Laravel
- Php artisan make model, factory, migration and controller in single command
- Trying to access array offset on value of type null error in laravel
- How to get single column value in laravel
- Return view from route Laravel
- How to get data from two tables in laravel
- How to remove P tag from CkEditor in Laravel?
- Create records using relationship in laravel
- Sample configuration files to create laravel project with docker using wsl (window subsystem linux)
- How to update record after save method in Laravel
- Illuminate\Database\QueryException could not find driver
- Remove several global scope from query
- Extra Filter Query on Relationships in Laravel
- Create a record if not exist in laravel
- How to get last year records count with month wise in Laravel
- How to create event and listener in laravel ?
- How to add background image to div using Tailwindcss, Vite in Laravel Environment
- How to include header file in laravel
- Laravel upload file with original file name
- In order to use the Auth::routes() method, please install the laravel/ui package
- Laravel 10 starter app using breeze on live server
- Call to undefined method App\Models\User::follow()
- Laravel 10 Breeze Authentication Example