Actions
Introduction
Filament's tables can use Actions. They are buttons that can be added to the end of any table row, or even in the header or toolbar of a table. For instance, you may want an action to "create" a new record in the header, and then "edit" and "delete" actions on each row. Bulk actions can be used to execute code when records in the table are selected. Additionally, actions can be added to any table column, such that each cell in that column is a trigger for your action.
It's highly advised that you read the documentation about customizing action trigger buttons and action modals to that you are aware of the full capabilities of actions.
Record actions
Action buttons can be rendered at the end of each table row. You can put them in the $table->recordActions()
method:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->recordActions([
// ...
]);
}
Actions may be created using the static make()
method, passing its unique name.
You can then pass a function to action()
which executes the task, or a function to url()
which creates a link:
use App\Models\Post;
use Filament\Actions\Action;
Action::make('edit')
->url(fn (Post $record): string => route('posts.edit', $record))
->openUrlInNewTab()
Action::make('delete')
->requiresConfirmation()
->action(fn (Post $record) => $record->delete())
All methods on the action accept callback functions, where you can access the current table $record
that was clicked.

Positioning record actions before columns
By default, the record actions in your table are rendered in the final cell of each row. You may move them before the columns by using the position
argument:
use Filament\Tables\Enums\RecordActionsPosition;
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->recordActions([
// ...
], position: RecordActionsPosition::BeforeColumns);
}

Positioning record actions before the checkbox column
By default, the record actions in your table are rendered in the final cell of each row. You may move them before the checkbox column by using the position
argument:
use Filament\Tables\Enums\RecordActionsPosition;
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->recordActions([
// ...
], position: RecordActionsPosition::BeforeCells);
}

Accessing the selected table rows
You may want an action to be able to access all the selected rows in the table. Usually, this is done with a bulk action in the header of the table. However, you may want to do this with a row action, where the selected rows provide context for the action.
For example, you may want to have a row action that copies the row data to all the selected records. To force the table to be selectable, even if there aren't bulk actions defined, you need to use the selectable()
method. To allow the action to access the selected records, you need to use the accessSelectedRecords()
method. Then, you can use the $selectedRecords
parameter in your action to access the selected records:
use Filament\Actions\Action;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
public function table(Table $table): Table
{
return $table
->selectable()
->recordActions([
Action::make('copyToSelected')
->accessSelectedRecords()
->action(function (Model $record, Collection $selectedRecords) {
$selectedRecords->each(
fn (Model $selectedRecord) => $selectedRecord->update([
'is_active' => $record->is_active,
]),
);
}),
]);
}
Bulk actions
Tables also support "bulk actions". These can be used when the user selects rows in the table. Traditionally, when rows are selected, a "bulk actions" button appears. When the user clicks this button, they are presented with a dropdown menu of actions to choose from. You can put them in the $table->toolbarActions()
or $table->headerActions()
methods:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->toolbarActions([
// ...
]);
}
Bulk actions may be created using the static make()
method, passing its unique name. You should then pass a callback to action()
which executes the task:
use Filament\Actions\BulkAction;
use Illuminate\Database\Eloquent\Collection;
BulkAction::make('delete')
->requiresConfirmation()
->action(fn (Collection $records) => $records->each->delete())
The function allows you to access the current table $records
that are selected. It is an Eloquent collection of models.
