listener not working via echo

I've a custom page in filament whose view is here:
<x-filament-panels::page>
{{ $record->name }}

@foreach ($record->unAnsweredChatSessions as $chatSession)
<a href="#" wire:click="fetchMessages({{ $chatSession->id }})">
{{ $chatSession->oldestMessage->message }}
</a>
<br />
@endforeach

@if ($selectChatSessionId > 0)
<div>
<h2>Chat Session with {{ $selectChatSessionId }}</h2>
<div>
@foreach ($selectedSessionMessages->messages as $message)
<div>
{{ $message->message }} <br><br>
</div>
@endforeach
</div>
<input type="text" wire:model="newMessage" />
<input type="submit" wire:click="sendMessage" />
</div>
@endif
</x-filament-panels::page>
@script
<script type="module">
Echo.private(`new-chat-for-{{ $selectChatSessionId }}`)
.listen('adminchatnotification', (e) => {
$wire.$refresh()
});
</script>
@endscript
<x-filament-panels::page>
{{ $record->name }}

@foreach ($record->unAnsweredChatSessions as $chatSession)
<a href="#" wire:click="fetchMessages({{ $chatSession->id }})">
{{ $chatSession->oldestMessage->message }}
</a>
<br />
@endforeach

@if ($selectChatSessionId > 0)
<div>
<h2>Chat Session with {{ $selectChatSessionId }}</h2>
<div>
@foreach ($selectedSessionMessages->messages as $message)
<div>
{{ $message->message }} <br><br>
</div>
@endforeach
</div>
<input type="text" wire:model="newMessage" />
<input type="submit" wire:click="sendMessage" />
</div>
@endif
</x-filament-panels::page>
@script
<script type="module">
Echo.private(`new-chat-for-{{ $selectChatSessionId }}`)
.listen('adminchatnotification', (e) => {
$wire.$refresh()
});
</script>
@endscript
I am successfully able to dispatch an event CustomerAskedQuestion using laravel event. But I am not able to listen to it in this above mentioned filament custom page view file, neither in the class file like below:
public function getListeners()
{
return [
"echo:adminchatnotification,.new-chat-for-{$this->selectChatSessionId}" => 'fetchMessages',
];
}

public function fetchMessages($selectChatSessionId)
{
dd('event captured');
}
public function getListeners()
{
return [
"echo:adminchatnotification,.new-chat-for-{$this->selectChatSessionId}" => 'fetchMessages',
];
}

public function fetchMessages($selectChatSessionId)
{
dd('event captured');
}
I get Laravel Echo not found error, not sure what should I do to mitigate this error? Noob question I believe?
2 Replies
Daniel Reales
Daniel Reales10mo ago
Could you resolve it?
lordjackson
lordjackson2w ago
Hello guys, I was able to solve this error following this tutorial, I hope it helps you too. https://laraveldaily.com/post/configure-laravel-reverb-filament-broadcasting
Want results from more Discord servers?
Add your server