Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mcalonje's avatar

Are filament stand alone tables compatible with Spatie Query Builder?

I would like to build a table on my website (outside Filament admin panel) that is populated by URL requests. I have implemented this using Spatie Query Builder , so that I get a table based on the url request such as Spatie's example below:

/users?filter[name]=John:

I have also been able to use a filament table outside of the admin panel which appears functional (although its styling has been hijacked by that of Jetstream which is what I'm using as a scaffolding for the website).

However, I haven't been able to use a Spatie Query builder query to populate the Filament table and I'm not sure this is possible.

It appears that Filament creator Dan Harrin is working on some 'Query Builder' functionality for Filament.

Is this upcoming Filament functionality what I need to wait for to be able to have the initial query for the table based on the URL request, with subsequent filtering using Filament, or is there a way to do it with Spatie Query Builder combined with filament table builder?

Thanks!

0 likes
1 reply
LaryAI's avatar
Level 58

Based on the information provided, it seems that the user wants to know if it is possible to use Spatie Query Builder to populate a Filament table outside of the admin panel.

Unfortunately, Filament does not currently have built-in support for Spatie Query Builder. However, you can still achieve the desired functionality by manually populating the Filament table using the data retrieved from the Spatie Query Builder.

Here's a possible solution:

  1. Retrieve the data using Spatie Query Builder based on the URL request.
  2. Format the retrieved data into the required format for the Filament table.
  3. Pass the formatted data to the Filament table builder to populate the table.

Here's an example of how you can achieve this using PHP:

use Spatie\QueryBuilder\QueryBuilder;

// Step 1: Retrieve the data using Spatie Query Builder
$query = QueryBuilder::for(User::class)
    ->allowedFilters('name')
    ->defaultSort('name')
    ->get();

// Step 2: Format the retrieved data
$formattedData = [];
foreach ($query as $user) {
    $formattedData[] = [
        'name' => $user->name,
        // Add more columns as needed
    ];
}

// Step 3: Pass the formatted data to the Filament table builder
$table = Filament\Tables\Table::make()
    ->data($formattedData)
    ->columns([
        Filament\Tables\Columns\Text::make('name'),
        // Add more columns as needed
    ]);

// Render the table
echo $table->render();

Note that this is just a basic example, and you may need to modify it based on your specific requirements and the structure of your Filament table.

Keep in mind that this solution assumes you have already set up Filament and Spatie Query Builder in your project. If not, you will need to install and configure them accordingly.

I hope this helps! Let me know if you have any further questions.

Please or to participate in this conversation.