Avatar ·

How to get raw SQL query from Query Builder in Laravel?

Hello everyone! I'm new to Laravel and Eloquent, and I have a problem. I'm using Query Builder to build database queries, but I need to see what exact SQL query is generated as output. For example, I have this code: ```php $users = DB::table('users') ->where('active', 1) ->where('age', '>', 18) ->orderBy('name') ->get(); ``` I want to see the full SQL that is executed to debug it or check if JOINs are built correctly. I tried using `dd()` and `toSql()`, but for some reason they don't show related data or bindings. Is there a method that outputs the ready query with substituted values? Thanks in advance for your help! <<>>

Using toSql() and getBindings() methods

The most pr