Reuse action in both Table and Header
- Published: 17 Aug 2024 Updated: 17 Aug 2024
how to use an action as a headerAction or as a table row action without code duplication
With FilamentPHP, you can create an action and reuse it in multiple resources. Here is a quick example by @awcodes on how to create a reusable action.
But what if you need to reuse the same action in different places, such as in a header action and on a row table? This is not possible by default, as each one extends a different class.
Here’s how FilamentPHP handles this internally:
first, create a trait, Something like this:
Then create the header action:
and add the trait we just created:
and for the table row action:
This was originally shard by @leandrocfe.
Related Tricks:
Using an editable column like SelectColumn or ToggleColumn, you can conditionally trigger a modal form when a certain option is selected.
make all Field or any components translatable
Translating components can often be a repetitive task, Fortunately, there's a neat trick to automate this process, making your components instantly translatable.
how to make actions sticky in tables when you have a lot of columns