Dynamic Table Fields with Database Actions

Filament 4

In this example, we will show you how to create a Dynamic Filament resource table column using another model.

FilamentExamples ThumbBase (16)

Get the Source Code:

How it works

In this example, we require displaying a "Quick Action" to select which Country has the Product available.

For this, we need a few models:

  • Products - Our products list
  • Countries - Our countries list
  • Product Countries - An intermediate model, where we store selected data

Our main code will be inside our ProductTable file:

app/Filament/Resources/Products/Tables/ProductsTable.php

class ProductsTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('id'),
TextColumn::make('name'),
])
->filters([
//
])
->recordActions([
ViewAction::make(),
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
}

Here, we want to dynamically display the checkboxes for each country. This can be done using arrays:

app/Filament/Resources/Products/Tables/ProductsTable.php

class ProductsTable
{
// ...
}
The FULL tutorial is available after the purchase: in the Readme file of the official repository you would get invited to.
Get the Source Code: All 153 Premium Examples for $99