Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sindo's avatar
Level 2

Laravel 11 - Reverb with Listener class

I've been searching on this for a few days but I'm puzzled and completely lost in the meantime.

I have a reverb socket running via Herd. Connecting to it works, I can subscribe to a channel but when I try to send an event and catch it in the backend ... nothing happens. I have been looking at tutorials and followed that to no avail.

In my AppServiceProvider I added this to the boot() method:

I can see that message in the logfile - so that runs like it should.

MessageListener looks like this:

<?php

namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
use Laravel\Reverb\Events\MessageReceived;

class MessageListener
{
    /**
     * Create the event listener.
     */
    public function __construct()
    {
        Log::info('MessageListener constructed');
    }

    /**
     * Handle the event.
     */
    public function handle(MessageReceived $event): void
    {
        Log::info('Reverb message received', [
            'event_object' => get_object_vars($event)
        ]);
    }
}

But none of these logs appear in my logfile.

Any idea what I'm missing here? I'm sure it's something small and I'm going to kick myself.

Thanks!

0 likes
1 reply
LaryAI's avatar
Level 58

To troubleshoot the issue with your Laravel event listener not being triggered, let's go through a few steps to ensure everything is set up correctly:

  1. Verify Event Firing: Ensure that the MessageReceived event is actually being fired. You can do this by temporarily adding a log statement in the place where the event is dispatched. For example:

    use Laravel\Reverb\Events\MessageReceived;
    use Illuminate\Support\Facades\Log;
    
    // Somewhere in your code where the event is dispatched
    Log::info('Dispatching MessageReceived event');
    event(new MessageReceived($data));
    

    Check your logs to confirm that this message appears, indicating the event is being dispatched.

  2. Check Event and Listener Registration: Ensure that the event and listener are correctly registered. You've already added the listener in the AppServiceProvider, which is good. Double-check that the MessageReceived event is correctly imported and used in the right context.

  3. Listener Class: Make sure the MessageListener class is correctly set up to handle the event. You've already done this, but ensure there are no typos or namespace issues.

  4. Queue Configuration: If your listener implements ShouldQueue, ensure your queue worker is running. Since your listener does not implement ShouldQueue, this step might not be necessary unless you plan to queue the listener.

  5. Environment Configuration: Ensure that your environment is correctly set up to handle events and listeners. Sometimes, configuration issues can prevent events from being processed.

  6. Debugging: Add additional logging in the handle method of your listener to see if it's being called at all. You can also try simplifying the listener to see if it works with minimal logic.

  7. Check for Errors: Look for any errors in your logs that might indicate why the listener isn't being triggered. Sometimes, exceptions can prevent the listener from executing.

If after these steps the issue persists, consider creating a minimal example to isolate the problem. This can help identify if the issue is with the event, the listener, or the environment configuration.

Please or to participate in this conversation.