
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
- How to change default timestamp fields name in Laravel
- How to create project_user pivot table in laravel
- How to get single column value in laravel
- How to Get records between two dates in Laravel
- How to pass data to route in laravel?
- Laravel append URI in route
- Undefined property: stdClass::$title
- How to get only time from created_at in laravel
- Redirect from www to non www in laravel using htaccess
- Call to a member function pluck() on array
- How to get images from AWS s3 and display in Laravel blade
- How to add a key value pair to existing array in laravel
- How to create laravel project using composer
- How to upload multiple images after preview in laravel using cropper js
- How to remove package from laravel
- Composer\Exception\NoSslException
- How to restore deleted records in laravel
- How to get column names from table in Laravel
- Automatically remove records using Prunable trait in Laravel
- Laravel 5.4 save data to database
- How to create controller in laravel
- How to add unique records in pivot columns of Laravel pivot table
- Get id of last inserted record in laravel
- How to check data inserted or deleted in pivot after toggle method
- Update record after find method in lavavel