Very Simple SQL Dump In Laravel

profile picture

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 !

about me

profile picture

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 me

follow me

newsletter

A weekly email with the latests articles

support my work

Start trading on binance
  • BTC

    BTC

    bc1qgw9a8hyqqwvcls9ln7vhql4mad0qkveutr2td7

  • ETH

    ETH

    0x3A720717Da03dB6f3c4a4Ff08BC64100205A79d0

recent posts

DDOS By Web Crawlers

1
1 year ago

Something Given

1
1 year ago

2025 © My Dynamic Production SRL All rights Reserved.