Reusing actions
Is there any documentation on how to make a reusable actions? I find myself configuring the "empty table action" and "attach action" often the same.
11 Replies
Make a class and use the
setUp()
method for configurationHow do I include it then? Like this?
My question was if there is any documentation on creating reusable actions. Guessing the answer to that is no?
No. The same as the other actions.
There is no documentation. Have a look at the existing actions.
here's an example of a reusable action: https://gist.github.com/awcodes/eda694866e62ff3287df2bd46610e7ba
Couple more here π
https://github.com/saade/filament-autograph/tree/3.x/src/Forms/Components/Actions
Thanks guys!
What about an action that can be used as a table action or a "standalone" action on a livewire component?
I have the same functionality, rating a ratable resource, that displays a modal dialog box, and allows a user to enter/clear a rating.
It seems I need to extend a Table Action to use as a table row action, which makes sense, but then it's not something that can be used on the standalone livewire component.
I'm thinking I need multiple action classes, each extending the appropriate filament action class, but then it's not quite clear which way is the best way to reuse all of the basic/shared functionality.
Would probably use a shared trait on the two separate action classes.
Thx. I've considered that. I have a Table Action action that uses the setup to get everything working nicely for a table record that I want to be able to rate. It works great. But, many of the "handlers" take a "record", which is the record in question. I am not sure how I can have a non-table action work without this being provided.
(Hopefully that makes sense. I haven't yet tried it. I've just got my single Table Action action working. I need to try to extract the setup functionality to a trait and then try it with the livewire component action, which uses
Filament\Actions\Action
and instead of taking $record
, it uses the livewire component's public $ratable
attribute/property.)
Maybe I change public $ratable
to public $record
and then refer to $this->record
in the trait rather than have filament inject/pass it...? π€If itβs only these two actions, might be easier just to have the duplication if its only going to be used in these two actions.
Good point. Annoying, but good point. π