Setting up the Livewire component
First, generate a new Livewire component:InteractsWithActions and InteractsWithSchemas traits, and implement the HasActions and HasSchemas interfaces on your Livewire component class:
Adding the action
Add a method that returns your action. The method must share the exact same name as the action, or the name followed byAction:
{{ $this->deleteAction }}, where you replace deleteAction with the name of your action method:
<x-filament-actions::modals /> which injects the HTML required to render action modals. This only needs to be included within the Livewire component once, regardless of how many actions you have for that component.
filament/actions also includes the following packages:filament/formsfilament/infolistsfilament/notificationsfilament/support
@livewire('notifications') in your layout and add @import '../../vendor/filament/notifications/resources/css/index.css' to your CSS file.If you are using any other Filament components in your action, make sure to install and integrate the corresponding package as well.Passing action arguments
Sometimes, you may wish to pass arguments to your action. For example, if you’re rendering the same action multiple times in the same view, but each time for a different model, you could pass the model ID as an argument, and then retrieve it later. To do this, you can invoke the action in your view and pass in the arguments as an array:Hiding actions in a Livewire view
If you usehidden() or visible() to control if an action is rendered, you should wrap the action in an @if check for isVisible():
hidden() and visible() methods also control if the action is disabled(), so they are still useful to protect the action from being run if the user does not have permission. Encapsulating this logic in the hidden() or visible() of the action itself is good practice otherwise you need to define the condition in the view and in disabled().
You can also take advantage of this to hide any wrapping elements that may not need to be rendered if the action is hidden:
Grouping actions in a Livewire view
You may group actions together into a dropdown menu by using the<x-filament-actions::group> Blade component, passing in the actions array as an attribute:
Chaining actions
You can chain multiple actions together, by calling thereplaceMountedAction() method to replace the current action with another when it has finished:
Programmatically triggering actions
Sometimes you may need to trigger an action without the user clicking on the built-in trigger button, especially from JavaScript. Here is an example action which could be registered on a Livewire component:wire:click attribute, calling the mountAction() method and optionally passing in any arguments that you want to be available:
$wire utility, passing in the same arguments: