Understand Eloquent by Checking QueryLog

Posted: 2025/04/25
Updated: 2025/04/30

To understand what happens under the hood when using Eloquent, I can use Tinker and enable QueryLog with this command

DB::enableQueryLog();

Then after playing around with Eloquent, I can check the log to see what SQL was using for each Eloquent command

DB:getQueryLog();

Alternatively, I can check the SQL query immediate by using this command


DB::listen(function ($sql) {var_dump($sql->sql, $sql->bindings);});

No comments yet

Leave your comment

Search
Side Widget
You can put anything you want inside of these side widgets. They are easy to use, and feature the Bootstrap 5 card component!