Skip to content
Version 5.x
Theme

Overview

View as Markdown

On this page

#Introduction

Actions combine a trigger button with the code to run when it is clicked. They can also open a modal to collect input or request confirmation. For example, this action confirms before deleting a client:

use Filament\Actions\Action;

Action::make('delete')
    ->requiresConfirmation()
    ->action(fn () => $this->client->delete())

Warning

If $client or $post in these examples is stored in a public Livewire property, Filament does not re-query or authorize it on later requests. Re-query and authorize the model before using it in an action, including any tenant or ownership restrictions your application requires. See Eloquent model restoration in Livewire for more information. For URL actions, authorize access in the destination route or page.

To collect input before running an action, define its modal's schema. The submitted data is available in the action() function:

use Filament\Actions\Action;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\TextInput;
use Illuminate\Support\Facades\Mail;

Action::make('sendEmail')
    ->schema([
        TextInput::make('subject')->required(),
        RichEditor::make('body')->required(),
    ])
    ->action(function (array $data) {
        Mail::to($this->client)
            ->send(new GenericEmail(
                subject: $data['subject'],
                body: $data['body'],
            ));
    })

As well as $data, the action() function can inject various utilities as parameters.

Action $action Filament\Actions\Action

The current action instance.

Arguments $arguments array<string, mixed>

The array of arguments passed to the action when it was triggered.

Data $data array<string, mixed>

The array of data submitted from form fields in the action's modal. It will be empty before the modal form is submitted.

Livewire $livewire Livewire\Component

The Livewire component instance.

Eloquent model FQN $model ?string<Illuminate\Database\Eloquent\Model>

The Eloquent model FQN for the current action, if one is attached.

Mounted actions $mountedActions array<Filament\Actions\Action>

The array of actions that are currently mounted in the Livewire component. This is useful for accessing data from parent actions.

Parent action $parentAction ?Filament\Actions\Action

The mounted parent action, or the containing parent action if one exists.

Record $record Illuminate\Database\Eloquent\Model|array<string, mixed>|null

The Eloquent record or custom data array for the current action, if one is attached.

Schema $schema Filament\Schemas\Schema

[Actions in schemas only] The schema object that this action belongs to.

Schema component $schemaComponent Filament\Schemas\Components\Component

[Actions in schemas only] The schema component that this action belongs to.

Schema component state $schemaComponentState mixed

[Actions in schemas only] The current value of the schema component.

Schema get function $schemaGet Filament\Schemas\Components\Utilities\Get

[Actions in schemas only] A function for retrieving values from the schema data. Validation is not run on form fields.

Schema operation $schemaOperation string

[Actions in schemas only] The current operation being performed by the schema. Usually create, edit, or view.

Schema set function $schemaSet Filament\Schemas\Components\Utilities\Set

[Actions in schemas only] A function for setting values in the schema data.

Schema state $schemaState mixed

[Actions in schemas only] The current value of the schema that this action belongs to, like the current repeater item.

Selected Eloquent records $selectedRecords Illuminate\Support\Collection|Illuminate\Support\LazyCollection

[Actions in tables only] The selected records, filtered by individual record authorization when it is enabled. Requires accessSelectedRecords().

Selected Eloquent records query $selectedRecordsQuery Illuminate\Database\Eloquent\Builder

[Actions in Eloquent-query-backed tables only] The query for the selected records. Requires accessSelectedRecords(). Individual record authorization has not been applied to this query.

Table $table Filament\Tables\Table

[Actions in tables only] The table object that this action belongs to.

Actions usually run without navigating away from the page. To make a trigger link to another page instead, use url():

use Filament\Actions\Action;

Action::make('edit')
    ->url(fn (): string => route('posts.edit', ['post' => $this->post]))

As well as allowing a static value, the url() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.

Action $action Filament\Actions\Action

The current action instance.

Arguments $arguments array<string, mixed>

The array of arguments passed to the action when it was triggered.

Data $data array<string, mixed>

The array of data submitted from form fields in the action's modal. It will be empty before the modal form is submitted.

Livewire $livewire Livewire\Component

The Livewire component instance.

Eloquent model FQN $model ?string<Illuminate\Database\Eloquent\Model>

The Eloquent model FQN for the current action, if one is attached.

Mounted actions $mountedActions array<Filament\Actions\Action>

The array of actions that are currently mounted in the Livewire component. This is useful for accessing data from parent actions.

Parent action $parentAction ?Filament\Actions\Action

The mounted parent action, or the containing parent action if one exists.

Record $record Illuminate\Database\Eloquent\Model|array<string, mixed>|null

The Eloquent record or custom data array for the current action, if one is attached.

Schema $schema Filament\Schemas\Schema

[Actions in schemas only] The schema object that this action belongs to.

Schema component $schemaComponent Filament\Schemas\Components\Component

[Actions in schemas only] The schema component that this action belongs to.

Schema component state $schemaComponentState mixed

[Actions in schemas only] The current value of the schema component.

Schema get function $schemaGet Filament\Schemas\Components\Utilities\Get

[Actions in schemas only] A function for retrieving values from the schema data. Validation is not run on form fields.

Schema operation $schemaOperation string

[Actions in schemas only] The current operation being performed by the schema. Usually create, edit, or view.

Schema set function $schemaSet Filament\Schemas\Components\Utilities\Set

[Actions in schemas only] A function for setting values in the schema data.

Schema state $schemaState mixed

[Actions in schemas only] The current value of the schema that this action belongs to, like the current repeater item.

Selected Eloquent records $selectedRecords Illuminate\Support\Collection|Illuminate\Support\LazyCollection

[Actions in tables only] The selected records, filtered by individual record authorization when it is enabled. Requires accessSelectedRecords().

Selected Eloquent records query $selectedRecordsQuery Illuminate\Database\Eloquent\Builder

[Actions in Eloquent-query-backed tables only] The query for the selected records. Requires accessSelectedRecords(). Individual record authorization has not been applied to this query.

Table $table Filament\Tables\Table

[Actions in tables only] The table object that this action belongs to.

Caution

If you are passing user-controlled data to the url() method, you should validate that the URL does not use a dangerous scheme such as javascript: or data:. Failing to do so could expose your application to XSS attacks. The simplest way to guard against this is to wrap the value in Filament's Str::sanitizeUrl() helper, which returns null for any URL that does not use http/https (or a relative path).

The entire look of the action's trigger button and the modal is customizable using fluent PHP methods. We provide a sensible and consistent styling for the UI, but all of this is customizable with CSS.

#Available actions

Filament includes several actions that you can add to your app. Their aim is to simplify the most common Eloquent-related actions:

You can also create your own actions to do anything, these are just common ones that we include out of the box.

#Choosing a trigger style

Out of the box, action triggers have 4 styles - "button", "link", "icon button", and "badge".

"Button" triggers have a background color, label, and optionally an icon. Usually, this is the default button style, but you can use it manually with the button() method:

use Filament\Actions\Action;

Action::make('edit')
    ->button()
Button trigger

"Link" triggers have no background color. They must have a label and optionally an icon. They look like a link that you might find embedded within text. You can switch to that style with the link() method:

use Filament\Actions\Action;

Action::make('edit')
    ->link()
Link trigger

"Icon button" triggers are circular buttons with an icon and no label. You can switch to that style with the iconButton() method:

use Filament\Actions\Action;

Action::make('edit')
    ->icon('heroicon-m-pencil-square')
    ->iconButton()
Icon button trigger

"Badge" triggers have a background color, label, and optionally an icon. You can use a badge as trigger using the badge() method:

use Filament\Actions\Action;

Action::make('edit')
    ->badge()
Badge trigger

#Using an icon button on mobile devices only

You may want to use a button style with a label on desktop, but remove the label on mobile. This will transform it into an icon button. You can do this with the labeledFrom() method, passing in the responsive breakpoint at which you want the label to be added to the button:

use Filament\Actions\Action;

Action::make('edit')
    ->icon('heroicon-m-pencil-square')
    ->button()
    ->labeledFrom('md')

#Setting a label

By default, the label of the trigger button is generated from its name. You may customize this using the label() method:

use Filament\Actions\Action;

Action::make('edit')
    ->label('Edit post')
    ->url(fn (): string => route('posts.edit', ['post' => $this->post]))

As well as allowing a static value, the label() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.

Action $action Filament\Actions\Action

The current action instance.

Arguments $arguments array<string, mixed>

The array of arguments passed to the action when it was triggered.

Data $data array<string, mixed>

The array of data submitted from form fields in the action's modal. It will be empty before the modal form is submitted.

Livewire $livewire Livewire\Component

The Livewire component instance.

Eloquent model FQN $model ?string<Illuminate\Database\Eloquent\Model>

The Eloquent model FQN for the current action, if one is attached.

Mounted actions $mountedActions array<Filament\Actions\Action>

The array of actions that are currently mounted in the Livewire component. This is useful for accessing data from parent actions.

Parent action $parentAction ?Filament\Actions\Action

The mounted parent action, or the containing parent action if one exists.

Record $record Illuminate\Database\Eloquent\Model|array<string, mixed>|null

The Eloquent record or custom data array for the current action, if one is attached.

Schema $schema Filament\Schemas\Schema

[Actions in schemas only] The schema object that this action belongs to.

Schema component $schemaComponent Filament\Schemas\Components\Component

[Actions in schemas only] The schema component that this action belongs to.

Schema component state $schemaComponentState mixed

[Actions in schemas only] The current value of the schema component.

Schema get function $schemaGet Filament\Schemas\Components\Utilities\Get

[Actions in schemas only] A function for retrieving values from the schema data. Validation is not run on form fields.

Schema operation $schemaOperation string

[Actions in schemas only] The current operation being performed by the schema. Usually create, edit, or view.

Schema set function $schemaSet Filament\Schemas\Components\Utilities\Set

[Actions in schemas only] A function for setting values in the schema data.

Schema state $schemaState mixed

[Actions in schemas only] The current value of the schema that this action belongs to, like the current repeater item.

Selected Eloquent records $selectedRecords Illuminate\Support\Collection|Illuminate\Support\LazyCollection

[Actions in tables only] The selected records, filtered by individual record authorization when it is enabled. Requires accessSelectedRecords().

Selected Eloquent records query $selectedRecordsQuery Illuminate\Database\Eloquent\Builder

[Actions in Eloquent-query-backed tables only] The query for the selected records. Requires accessSelectedRecords(). Individual record authorization has not been applied to this query.

Table $table Filament\Tables\Table

[Actions in tables only] The table object that this action belongs to.

#Setting a color

Buttons may have a color to indicate their significance:

use Filament\Actions\Action;

Action::make('delete')
    ->color('danger')

As well as allowing a static value, the color() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.

Action $action Filament\Actions\Action

The current action instance.

Arguments $arguments array<string, mixed>

The array of arguments passed to the action when it was triggered.

Data $data array<string, mixed>

The array of data submitted from form fields in the action's modal. It will be empty before the modal form is submitted.

Livewire $livewire Livewire\Component

The Livewire component instance.

Eloquent model FQN $model ?string<Illuminate\Database\Eloquent\Model>

The Eloquent model FQN for the current action, if one is attached.

Mounted actions $mountedActions array<Filament\Actions\Action>

The array of actions that are currently mounted in the Livewire component. This is useful for accessing data from parent actions.

Parent action $parentAction ?Filament\Actions\Action

The mounted parent action, or the containing parent action if one exists.

Record $record Illuminate\Database\Eloquent\Model|array<string, mixed>|null

The Eloquent record or custom data array for the current action, if one is attached.

Schema $schema Filament\Schemas\Schema

[Actions in schemas only] The schema object that this action belongs to.

Schema component $schemaComponent Filament\Schemas\Components\Component

[Actions in schemas only] The schema component that this action belongs to.

Schema component state $schemaComponentState mixed

[Actions in schemas only] The current value of the schema component.

Schema get function $schemaGet Filament\Schemas\Components\Utilities\Get

[Actions in schemas only] A function for retrieving values from the schema data. Validation is not run on form fields.

Schema operation $schemaOperation string

[Actions in schemas only] The current operation being performed by the schema. Usually create, edit, or view.

Schema set function $schemaSet Filament\Schemas\Components\Utilities\Set

[Actions in schemas only] A function for setting values in the schema data.

Schema state $schemaState mixed

[Actions in schemas only] The current value of the schema that this action belongs to, like the current repeater item.

Selected Eloquent records $selectedRecords Illuminate\Support\Collection|Illuminate\Support\LazyCollection

[Actions in tables only] The selected records, filtered by individual record authorization when it is enabled. Requires accessSelectedRecords().

Selected Eloquent records query $selectedRecordsQuery Illuminate\Database\Eloquent\Builder

[Actions in Eloquent-query-backed tables only] The query for the selected records. Requires accessSelectedRecords(). Individual record authorization has not been applied to this query.

Table $table Filament\Tables\Table

[Actions in tables only] The table object that this action belongs to.

Red trigger

#Setting a size

Buttons come in 3 sizes - Size::Small, Size::Medium or Size::Large. You can change the size of the action's trigger using the size() method:

use Filament\Actions\Action;
use Filament\Support\Enums\Size;

Action::make('create')
    ->size(Size::Large)

As well as allowing a static value, the size() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.

Action $action Filament\Actions\Action

The current action instance.

Arguments $arguments array<string, mixed>

The array of arguments passed to the action when it was triggered.

Data $data array<string, mixed>

The array of data submitted from form fields in the action's modal. It will be empty before the modal form is submitted.

Livewire $livewire Livewire\Component

The Livewire component instance.

Eloquent model FQN $model ?string<Illuminate\Database\Eloquent\Model>

The Eloquent model FQN for the current action, if one is attached.

Mounted actions $mountedActions array<Filament\Actions\Action>

The array of actions that are currently mounted in the Livewire component. This is useful for accessing data from parent actions.

Parent action $parentAction ?Filament\Actions\Action

The mounted parent action, or the containing parent action if one exists.

Record $record Illuminate\Database\Eloquent\Model|array<string, mixed>|null

The Eloquent record or custom data array for the current action, if one is attached.

Schema $schema Filament\Schemas\Schema

[Actions in schemas only] The schema object that this action belongs to.

Schema component $schemaComponent Filament\Schemas\Components\Component

[Actions in schemas only] The schema component that this action belongs to.

Schema component state $schemaComponentState mixed

[Actions in schemas only] The current value of the schema component.

Schema get function $schemaGet Filament\Schemas\Components\Utilities\Get

[Actions in schemas only] A function for retrieving values from the schema data. Validation is not run on form fields.

Schema operation $schemaOperation string

[Actions in schemas only] The current operation being performed by the schema. Usually create, edit, or view.

Schema set function $schemaSet Filament\Schemas\Components\Utilities\Set

[Actions in schemas only] A function for setting values in the schema data.

Schema state $schemaState mixed

[Actions in schemas only] The current value of the schema that this action belongs to, like the current repeater item.

Selected Eloquent records $selectedRecords Illuminate\Support\Collection|Illuminate\Support\LazyCollection

[Actions in tables only] The selected records, filtered by individual record authorization when it is enabled. Requires accessSelectedRecords().

Selected Eloquent records query $selectedRecordsQuery Illuminate\Database\Eloquent\Builder

[Actions in Eloquent-query-backed tables only] The query for the selected records. Requires accessSelectedRecords(). Individual record authorization has not been applied to this query.

Table $table Filament\Tables\Table

[Actions in tables only] The table object that this action belongs to.

Large trigger

#Setting an icon

Buttons may have an icon to add more detail to the UI. You can set the icon using the icon() method:

use Filament\Actions\Action;

Action::make('edit')
    ->url(fn (): string => route('posts.edit', ['post' => $this->post]))
    ->icon('heroicon-m-pencil-square')

As well as allowing a static value, the icon() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.

Action $action Filament\Actions\Action

The current action instance.

Arguments $arguments array<string, mixed>

The array of arguments passed to the action when it was triggered.

Data $data array<string, mixed>

The array of data submitted from form fields in the action's modal. It will be empty before the modal form is submitted.

Livewire $livewire Livewire\Component

The Livewire component instance.

Eloquent model FQN $model ?string<Illuminate\Database\Eloquent\Model>

The Eloquent model FQN for the current action, if one is attached.

Mounted actions $mountedActions array<Filament\Actions\Action>

The array of actions that are currently mounted in the Livewire component. This is useful for accessing data from parent actions.

Parent action $parentAction ?Filament\Actions\Action

The mounted parent action, or the containing parent action if one exists.

Record $record Illuminate\Database\Eloquent\Model|array<string, mixed>|null

The Eloquent record or custom data array for the current action, if one is attached.

Schema $schema Filament\Schemas\Schema

[Actions in schemas only] The schema object that this action belongs to.

Schema component $schemaComponent Filament\Schemas\Components\Component

[Actions in schemas only] The schema component that this action belongs to.

Schema component state $schemaComponentState mixed

[Actions in schemas only] The current value of the schema component.

Schema get function $schemaGet Filament\Schemas\Components\Utilities\Get

[Actions in schemas only] A function for retrieving values from the schema data. Validation is not run on form fields.

Schema operation $schemaOperation string

[Actions in schemas only] The current operation being performed by the schema. Usually create, edit, or view.

Schema set function $schemaSet Filament\Schemas\Components\Utilities\Set

[Actions in schemas only] A function for setting values in the schema data.

Schema state $schemaState mixed

[Actions in schemas only] The current value of the schema that this action belongs to, like the current repeater item.

Selected Eloquent records $selectedRecords Illuminate\Support\Collection|Illuminate\Support\LazyCollection

[Actions in tables only] The selected records, filtered by individual record authorization when it is enabled. Requires accessSelectedRecords().

Selected Eloquent records query $selectedRecordsQuery Illuminate\Database\Eloquent\Builder

[Actions in Eloquent-query-backed tables only] The query for the selected records. Requires accessSelectedRecords(). Individual record authorization has not been applied to this query.

Table $table Filament\Tables\Table

[Actions in tables only] The table object that this action belongs to.

Trigger with icon

You can also change the icon's position to be after the label instead of before it, using the iconPosition() method:

use Filament\Actions\Action;
use Filament\Support\Enums\IconPosition;

Action::make('edit')
    ->url(fn (): string => route('posts.edit', ['post' => $this->post]))
    ->icon('heroicon-m-pencil-square')
    ->iconPosition(IconPosition::After)

As well as allowing a static value, the iconPosition() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.

Action $action Filament\Actions\Action

The current action instance.

Arguments $arguments array<string, mixed>

The array of arguments passed to the action when it was triggered.

Data $data array<string, mixed>

The array of data submitted from form fields in the action's modal. It will be empty before the modal form is submitted.

Livewire $livewire Livewire\Component

The Livewire component instance.

Eloquent model FQN $model ?string<Illuminate\Database\Eloquent\Model>

The Eloquent model FQN for the current action, if one is attached.

Mounted actions $mountedActions array<Filament\Actions\Action>

The array of actions that are currently mounted in the Livewire component. This is useful for accessing data from parent actions.

Parent action $parentAction ?Filament\Actions\Action

The mounted parent action, or the containing parent action if one exists.

Record $record Illuminate\Database\Eloquent\Model|array<string, mixed>|null

The Eloquent record or custom data array for the current action, if one is attached.

Schema $schema Filament\Schemas\Schema

[Actions in schemas only] The schema object that this action belongs to.

Schema component $schemaComponent Filament\Schemas\Components\Component

[Actions in schemas only] The schema component that this action belongs to.

Schema component state $schemaComponentState mixed

[Actions in schemas only] The current value of the schema component.

Schema get function $schemaGet Filament\Schemas\Components\Utilities\Get

[Actions in schemas only] A function for retrieving values from the schema data. Validation is not run on form fields.

Schema operation $schemaOperation string