Raw Query Output With Bindings is Coming to Laravel 10
User::where(...)->ddRawSql();
// Using the new `toRawSql()` method
User::where('email', 'mandeep@example.com')->toRawSql();
// "SELECT * FROM users WHERE email = 'mandeep@example.com'"
There is some prior art before toRawSql()
—various developer tools (i.e., Laravel Debugbar) give you queries, and there's a dd()
method you can use as well:
// Using the dd() method
User::where('email', 'mandeep@example.com')->dd();
// "SELECT * FROM users WHERE email = ?"
// [
// 0 => "mandeep@example.com"
// ]