MyModel::where('bla', 1)->toSql();
Or you can use DB:listen()
DB::listen(function ($query) {
dump($query);
});
https://laravel.com/docs/5.8/database#listening-for-query-events
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I need to show somehow the sql queries, which is builded by laravel query builder. I can get them only when I purposely make an error (like write table(usrs) instead of table(users)), then I receive an laravel error message, that table usrs doesn't exist and the whole query there. But I believe, there is better way to get the query... ?
Of course. You can use either https://github.com/barryvdh/laravel-debugbar or https://github.com/itsgoingd/clockwork
Please or to participate in this conversation.