How to dispatch an event from a Notification Action
I've been trying to dispatch an event from a Notification Action but it's not working.
using ->dispatch or ->dispatchSelf seems to do nothing.
I've searched around and tried to use ->action() and dispatch using $livewire->dispatch() but action seems to not work on notification Actions.
How can I rly dispatch an event from a Notification action?
Further down in my Resource, there's my method that is attempting to listen to the dispatch event but it never gets there.
Any Thoughts?
12 Replies
I think you should use
dispatch()
instead of dispatchSelf
and be careful of the naming. You are dispatching test-created
and listening for test-event
I had to change some things around and forgot to change the name but it doesn't work still, not with dispatch() and not with dispatchSelf()
You have defined an ->action() method. So it won’t do anything on click.
Hello, I don't have an ->action() method on my Action.
he means you havent
That’s my point.
Actions aren’t livewire components so they aren’t going to just do a dispatch by themselves.
Oh sorry for my misunderstanding then, so what do you suggest? Have an action method as well as a dispatch one? I've tried to dispatch it from the ->action() method and my perception was that it doesn't even go into ->action() method, even a simple dd inside the ->action() method doesn't work.
Something like this, maybe.
I've already tried it, it's not working, even tried to just ->action(fn ($livewire) => dd($livewire) just to see if it was even getting inside the method but it's not
Can it be any behavior with it being a Notification Action?
possibly, it shouldn't matter though. sorry i don't have an app set up with notification's that i can test against at the moment.
hmm. according to the docs ->dispatch() should work.
Having the same issue, were you able to work around this @Hugo ?