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
- In order to use the Auth::routes() method, please install the laravel/ui package
- How to upload files to amazon s3 bucket using Laravel
- Get Array of IDs from Eloquent Collection
- How to pass data to multiple partial view files in laravel
- Use withCount() to get total number of records with relationship
- Create user in Laravel using tinker
- Get ids in array from users table
- Create project table with model and migration
- How to insert multiple rows in mysql using loop in laravel?
- Delete all related comments on deleting a post in Laravel
- Extra Filter Query on Relationships in Laravel
- How to get database name in Laravel 9 ?
- How to check if user has created any post or not in laravel
- How to avoid duplicate entries in pivot table in Laravel
- Generate random string lowercase in Laravel
- Method chaining in Laravel
- Class "App\Http\Controllers\Auth\Verified" not found
- How to make Copy or Duplicate table row in laravel
- How to add background image to div using Tailwindcss, Vite in Laravel Environment
- How to use bootstrap pagination in laravel 8
- Count all and get 10 records after where condition in laravel
- Permanently delete a record in laravel
- Update existing pivot table data in laravel
- Class 'Facade\Ignition\IgnitionServiceProvider' not found
- Route [password.request] not defined