
Trigger an action when updating a column's state
- Published: 28 Apr 2025 Updated: 28 Apr 2025
Using an editable column like SelectColumn or ToggleColumn, you can conditionally trigger a modal form when a certain option is selected.

Using an editable column like SelectColumn or ToggleColumn, you can conditionally trigger a modal form when a certain option is selected.
In this example, selecting a specific status (like "Redirected ") opens a modal with additional fields to fill, while other options simply update the record directly.
1public static function table(Table $table): Table
2{
3 return $table
4 ->columns([
5
6 Tables\Columns\SelectColumn::make('status')
7 ->updateStateUsing(function (string $state, Pages\ListPosts $livewire, Post $record) {
8 if ($state === PostStatus::REDIRECTED->value) {
9 $livewire->mountTableAction('redirectPost', $record->getKey()); // this will open the modal
10 } else {
11 $record->update(['status' => $state]);
12 }
13 })
14 ->options(PostStatus::class),
15
16 ])
17 ->actions([
18
19 Tables\Actions\Action::make('redirectPost')
20 ->fillForm(fn(Post $record) => ['redirect_id' => $record->redirect_id])
21 ->form([
22 Forms\Components\Select::make('redirect_id')
23 ->label('Redirect to')
24 ->relationship('redirectTo', 'title')
25 ->required(),
26 ])
27 ->action(fn($data, Post $record) => $record->update([
28 'status' => PostStatus::REDIRECTED,
29 'redirect_id' => $data[ 'redirect_id' ],
30 ]))
31
32 ]);
33}

Related Tricks:
make all Field or any components translatable
Learn how to implement row-level security in Filament tables using the applyRowAccessPolicy macro that filters query results based on user permissions through Laravel's policy system.
Using an editable column like SelectColumn or ToggleColumn, you can conditionally trigger a modal form when a certain option is selected.
how to make actions sticky in tables when you have a lot of columns