Is it possible to use Filament fields inside custom "Livewire" Action classes?
So, if you are aware of the Action classes that are implemented in a plugin similar to Jetstream, you might understand what I am speaking about. If not, I will explain.
In the hierarchy of a Custom Action class, first there is a registered class/callback such as an Interface using the
singleton()
design pattern. This Interface contains methods needed to implement the Action class. First, there is a Livewire Component that contains a method using Interface Injection variant of the Dependency Injection design pattern like this.
The Livewire Component:
This is then extended by the Action class like this:
My question:
Is it possible to use Filament fields in the Action class instead of what is used here so that Users of my package can change the fields without touching the blade view? If so, how could this be done?10 Replies
tbh I feel you are overcomplicating stuffs. Think Filament's Resource class
in your action class, implement a
getFormSchema
method that return an array of fields, then in your component Action::getFormSchema
to retrieve them
however sooner or later you might find you basically renaming Resource -> Action and doing the same thing by offering the customizing methods. Probably just publish as vendor load that if the file exist in userland, eg: App\Companies namespaceI wasn’t over complicating anything, I was just explaining exactly the layout of my package. I am a little confused on what you are saying though. Could you perhaps give me any examples that could work that won’t interfere with the entire flow of my data?
If possible
the way i write action classes is that they dont handle validation or authorization
they just "do" something
because its often contextual what validation applies
so i define my filament form like normal in livewire, call getState() and then pass that data into the action pre-validated
So are you saying I probably can’t pass the getFormSchema() into the Action class? I would also have to somehow mount the form data and pass it as well. The “update()” method in the Action class is essentially just an extension of the “updateCompanyName()” method in the Livewire component. But if not, could creating a dynamic component myself be a solution here?
Basically what Dan saying is
Think about the filament login page component. You have a default component to use out of the box, but for customization the user can extend it and register it
yeah
you could put the form schema in a method on the action class if you wanted
Usually Action/Service class gives a context of do something
but it would still be consumed and validated by the lw component
If you want to organize it, can have a Companies\Forms namespace/directory where you define class to have a method to return form schema like the resource class
That is essentially what my Action classes are for…
I’m not going to change the entire directory
But sounds good I’ll see if I can extend the formSchema to the action classes