Refresh a table when notification received
Is there any way to refresh a table when a broadcast notification is received?
Solution:Jump to solution
So I realised I can listen for a broadcast notification on the resource list class and then do something to the table to refresh it. My solution was to just set the tableSearch to itself which seems to work but feels a bit hacky
```
public function getListeners(): array
{
$user_id = auth()->user()->id;...
2 Replies
Solution
So I realised I can listen for a broadcast notification on the resource list class and then do something to the table to refresh it. My solution was to just set the tableSearch to itself which seems to work but feels a bit hacky
Nice solution @Matt Jenkins. If running on a Page you can call
->refresh()
on the table to refresh it - which is a bit cleaner than having to hack the tableSearch.
So this should work:
... although I do notice this won't work for a table in a widget so 🤷. In that case assigning tableSearch as you have works still so possibly better to stick with that.
For anyone else reading this, you can also use the #[On]
syntax if you don't need to inject variables into the channel name:
Finally - hopefully this point will help someone else. I have been using Model Broadcasting to broadcast, but couldn't for the life of me get Livewire (or even Echo directly) to respond to the broadcast event:
1. The event was broadcasting fine (appearing in Pusher debug console)
2. Filament/Livewire was connecting to the channel fine (appearing in the Push debug console)
3. Devtools was showing the websocket receiving the broadcast message fine
... however the event just would not fire. 🤔
I finally noticed I'd missed this: https://laravel.com/docs/11.x/broadcasting#listening-for-model-broadcasts
If using Model Broadcasting you must prefix the event name with a .
. So e.g. PostUpdated
becomes .PostUpdated
. Or it will fail silently.