logo light

Reuse action in both Table and Header

Image Description
By: Lara Zeus
  • 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

Reuse action in both Table and Header

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.

Back to Tricks