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
- Input file with max size validation in laravel
- Update record after find method in lavavel
- Laravel hasmany select not working
- Delete file from amazon s3 bucket using Laravel
- Call to undefined method Illuminate\Support\Facades\Request::all()
- How to display serial number in Laravel?
- Conditional validation in laravel
- Redirect from www to non www in laravel using htaccess
- How to display user profile after login in laravel
- How to create belongstomany relation using custom name on custom pivot table
- Submit form without CSRF token in Laravel
- How to Get records between two dates in Laravel
- If condition in foreach loop in laravel
- Laravel migration add foreign key to existing table
- FirstOrCreate() Not Inserting Model
- Target class [HomeController] does not exist
- Call to a member function update() on null
- Laravel create multiple records in Pivot table
- Laravel onclick function not working
- Route group with URI prefix using middleware and route name prefixes
- Get current URL on visit URL in Laravel
- How to check duplicate entry in laravel
- How to set column as primary key in Laravel model
- Page loader in laravel
- Always load the relationship data with eager loading in Laravel