Do you know Laravel have a new function that allow us to print out sql?
1 min readAug 29, 2023
In Laravel version 10 have release function toRawSql.
// Using the new `toRawSql()` method
User::where('email', 'foo@example.com')->toRawSql();
// "SELECT * FROM users WHERE email = 'foo@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', 'foo@example.com')->dd();
// "SELECT * FROM users WHERE email = ?"
// [
// 0 => "foo@example.com"
// ]
Read More Laravel Debugging Stories: