Very Simple SQL Dump In Laravel
Sometimes when you're working on a specific feature, or maybe a specific page of your website, or even a unit test, you're wondering about the SQL queries that are executed.
Laravel Eloquent is great and all but it can be difficult to clearly see what query is executed. This is very important because it might help you to greatly improve the performance of your application.
A very simple way to display every request is possible through this small snippet.
DB::listen(function ($query) {
dump($query->sql);
});
You can just paste this snippet at the top of your script and you're good to go!
This will obviously dump the query out on the page. You can choose to dump it on you terminal with beyondcode/laravel-dump-server
Another way would be to write all of that in your log file with the info()
helper like this:
DB::listen(function ($query) {
info($query->sql);
});
Happy debugging !
I consider myself as an IT Business Artisan. Or Consultant CTO. I'm a self-taught Web Developper, coach and teacher. My main work is helping and guiding digital startups.
more about meBTC
18SY81ejLGFuJ9KMWQu5zPrDGuR5rDiauM
ETH
0x519e0eaa9bc83018bb306880548b79fc0794cd08
XMR
895bSneY4eoZjsr2hN2CAALkUrMExHEV5Pbg8TJb6ejnMLN7js1gLAXQySqbSbfzjWHQpQhQpvFtojbkdZQZmM9qCFz7BXU
2024 © My Dynamic Production SRL All rights Reserved.