1 min read

Display the query from a Filament Table

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!