I’ve been playing around with Laravel Filament Tables and as I was building a really complex table with multiple filters, I noticed that I wanted to see what the query being generated was. So I hacked together a little thing to show it:

If, for some reason, you ever wanted to do this, I added a “getDebugSqlProperty” method on the Livewire Component that was taken from this tweet:

public function getDebugSqlProperty(): string
    return array_reduce($this->getFilteredTableQuery()->getBindings(), function ($sql, $binding) {
        return preg_replace('/\?/', is_numeric($binding)
            ? $binding
            : "'".$binding."'", $sql, 1);
    }, $this->getFilteredTableQuery()->toSql());

Then in the view call this Live computed property like this:

<pre><code>{{ $this->debugSql }}</code></pre>

Happy hacking!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s