Does anybody know if it's possible to view the generated SQL statement before executing it?
I know I can get the Query log however that is after the statement has been executed. I am looking for a way to get/view the generated SQL statement before it has been executed.
Any hints would be highly appreciated.
Have a look at the toSql()
method, i think this is what you want, but it will show you the query without any bindings
For example:
dd(User::where('id','=',5)->toSql())
will dump this:
select * from `users` where `id` = ?
You can get the sql by method \Illuminate\Database\Query\Builder::toSql()
Post::where('id', '>', 10)->toSql()
See demo https://implode.io/XDCq5G