F
Filamentβ€’14mo ago
F alko

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
Dennis Koch
Dennis Kochβ€’14mo ago
Make a class and use the setUp() method for configuration
F alko
F alkoOPβ€’14mo ago
How do I include it then? Like this?
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
CustomAction::setUp(),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
CustomAction::setUp(),
])
My question was if there is any documentation on creating reusable actions. Guessing the answer to that is no?
Dennis Koch
Dennis Kochβ€’14mo ago
No. The same as the other actions. There is no documentation. Have a look at the existing actions.
awcodes
awcodesβ€’14mo ago
Gist
NowAction
NowAction. GitHub Gist: instantly share code, notes, and snippets.
F alko
F alkoOPβ€’14mo ago
Thanks guys!
Travis
Travisβ€’11mo ago
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.
awcodes
awcodesβ€’11mo ago
Would probably use a shared trait on the two separate action classes.
Travis
Travisβ€’11mo ago
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...? πŸ€”
awcodes
awcodesβ€’11mo ago
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.
Travis
Travisβ€’11mo ago
Good point. Annoying, but good point. πŸ˜…
Want results from more Discord servers?
Add your server