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
Check the actions documentation https://filamentphp.com/docs/3.x/actions/trigger-button
Just like delete action. I want to create my custom action code in one place and use where ever I want
So create a custom action the same way...
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.
@Np you might find this helpful
https://gist.github.com/jlpellicer/ee8fb0f2b040a8e966cde64fe115eaa8#file-new_action-md
Gist
Filament & Laravel add new reusable actions
Filament & Laravel add new reusable actions. GitHub Gist: instantly share code, notes, and snippets.
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.
How can I create custom form action @awcodes
What do you want your "custom form action" to do?
I've only used FormActions as "Actions that open a Form in a Modal", as described in https://filamentphp.com/docs/3.x/forms/actions#adding-anonymous-actions-to-a-form-without-attaching-them-to-a-component
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.
I want to send email action where ever I want
Now I have Used in customer table only. But In future u may want to use in orders table
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).
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!
OK @krekas . I am new to discord communities. Thank you .
New isn't a reason
Will use markdown and follow the rules mentioned in the community. Thank you for guidance