How to add a method to a custom component?
Currently I am getting this error:
when I try to run a custom method called
saveCarState
when clicking on a button like:
I have followed this:
https://filamentphp.com/docs/3.x/forms/fields/custom
and created the custom component files (component class file and blade view class) via this command:
I can do the blade view and create bells and whistles.
But, in this custom component, I would like to bypass the form actions Save, Cancel, etc. and trigger my own Livewire functions.
So, I added `wire:click="saveCarState" on one of my buttons.
And I expect that when the user clicks on this button the function saveCarState in the file (that was created by the artisan command):
will be triggered.
So, I added it there like:
But I am getting the error message as I said in the beginning.
How can I use Livewire method in my custom component?
Clearly I am doing something wrong here πSolution:Jump to solution
saveCarState
method should exist in the CreatePage, EditPage, if you are using the panel builder, or in the LW component if you are using a custom LW component.5 Replies
Is this class file the correct file to put my custom functions in?
you would need the function
public function saveCarState() {
}
on the component
I already have it look:
I don't have any other files. Just the 2 Laravel command created.
Solution
saveCarState
method should exist in the CreatePage, EditPage, if you are using the panel builder, or in the LW component if you are using a custom LW component.Thanks! It works.