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:
how to make actions sticky in tables when you have a lot of columns
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 use a resource with multiple models
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.