
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 get path from current URL in Laravel
- Laravel create multiple records in Pivot table
- External link not working in laravel blade
- How to get route name on visit URL in laravel
- Display option of select as selected with blade directive Laravel
- How to decrypt laravel password
- Update last created record in Laravel
- Retain selected value of select box in Laravel
- Laravel delete all rows older than 30 days
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- Pagination in laravel
- How to show data by ID in laravel?
- Split an Eloquent Collection by half in Laravel
- How to access the nth object from Laravel collection object ?
- How to display HTML tags In Laravel blade
- Declaration of App\Models\Post::sluggable() must be compatible with Cviebrock\EloquentSluggable\Sluggable
- Create project factory and seed data in laravel
- Order by multiple columns in Laravel
- Trying to access array offset on value of type null error in laravel
- Page loader in laravel
- Method Illuminate\Database\Eloquent\Collection::appends does not exist
- Remove array keys and values if it does not exist in other array in Laravel
- How to get file extension from input type file in laravel
- Php artisan make model, factory, migration and controller in single command
- How to print form data in laravel