F
Filament•12mo ago
Np

custom action button can be used in multiple places

I want to create a custom action button to send email like a service. Can be used in where ever I want @Np
17 Replies
Np
NpOP•12mo ago
Just like delete action. I want to create my custom action code in one place and use where ever I want
toeknee
toeknee•12mo ago
So create a custom action the same way...
awcodes
awcodes•12mo ago
One action will not work in all places. There are FormAction, TableAction. And Action. You can resuse a form action in any form, a table action in any table and an action in any header. You just have to create the right action depending on where it will be used.
🤖transistor🤖
Gist
Filament & Laravel add new reusable actions
Filament & Laravel add new reusable actions. GitHub Gist: instantly share code, notes, and snippets.
DrByte
DrByte•12mo ago
Right. Like that gist implies: create your action-logic someplace that anything can call (an Actions namespace like that gist suggests, or a Service or even a self-invoking controller, or a Job ... whatever you decide is best). Then wherever you need an Action button that can "perform" that functionality, simply create the right Action/FormAction/TableAction for the context you're calling it from, and pass the right params (and data if any) to that central function to do it.
Np
NpOP•12mo ago
How can I create custom form action @awcodes
DrByte
DrByte•12mo ago
What do you want your "custom form action" to do?
DrByte
DrByte•12mo ago
But there are other types of form "actions" described in that same page as well. Where do you want the trigger "button" for this "form action" to be located? What record is it supposed to act on, if any? Knowing more about what your goals are will help give you a more accurate answer.
Np
NpOP•12mo ago
I want to send email action where ever I want
Np
NpOP•12mo ago
Now I have Used in customer table only. But In future u may want to use in orders table
No description
No description
DrByte
DrByte•12mo ago
Right. Those TableActions can be used in other Tables. You may have to provide the data parameters to the Action differently from different tables though. ie: customer table will know the email from the 'email' field in the customer record, but the Order table might need to look at the 'customer.email' field because it might be in the 'customer' relation instead directly in the order table (depends on your app structure).
krekas
krekas•12mo ago
Do you really expect someone will check your code in such horrible pictures? At least it was a screenshot. But real #✅┊rules and use markdown!
Np
NpOP•12mo ago
OK @krekas . I am new to discord communities. Thank you .
krekas
krekas•12mo ago
New isn't a reason
Np
NpOP•12mo ago
Will use markdown and follow the rules mentioned in the community. Thank you for guidance
Want results from more Discord servers?
Add your server