Avatar ·

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

Hello everyone. I'm new to Laravel and trying to debug a complex query using Query Builder. I need to see what exact SQL query Eloquent generates to verify that JOINs and WHEREs are built correctly. The problem is that I'm using `DB::table('users')->select(...)->where(...)->get()` and it works, but I want to see the final SQL before execution to make sure it's correct. For example, I have this code: ```php $users = DB::table('users') ->join('orders', 'users.id', '=', 'orders.user_id') ->where('users.active', 1) ->whereIn('orders.status', ['pending', 'processing']) ->orderBy('users.created_at', 'desc') ->get(); ``` I tried using `->toSql()`, but it returns the query with `?` placeholders instead of actual values.