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

User1980's avatar

Unable to get Laravel ECHO to receive event data in vue js

Hello everyone,

Been really struggling with this and I cannot find a way around. I am building a NON SPA which uses vues components inside blade files. The problem seems to come from vue js as I am sending correctly the event via the websockets. No errors showing in my vue console.

This is my vue front end.

    created() {
        window.Echo.private(`user.${this.userId}`)
            .listen('.SmartLight', (event) => {
                console.log(event.id);  //nothing received
                alert(event.id);  //nothing received

            });
}

My event:

<?php

namespace App\Events;

use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Queue\SerializesModels;

class SmartLight implements ShouldBroadcastNow
{
    use SerializesModels;

    public int $id;
    public array $userIds;

    /**
     * Create a new event instance.
     *
     * @param int $id
     * @param array $userIds
     * @return void
     */
    public function __construct(int $id, array $userIds)
    {
        $this->id = $id;
        $this->userIds = $userIds;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return array
     */
    public function broadcastOn(): array
    {
        // Create private channels for each user ID in the array
        $channels = [];

        foreach ($this->userIds as $userId) {
            $channels[] = new PrivateChannel("user.{$userId}");
        }
        return $channels;
    }

    /**
     * Get the data to broadcast.
     *
     * @return array
     */
    public function broadcastWith(): array
    {
        return [
            'id' => $this->id
        ];
    }
}

Telescope is detecting the event going out as:

{
"id": 135,
"userIds": [
376
]
}

I am also seeing the event going out on the websockets console as:

Channel: private-user.376, Event: App\Events\SmartLight

channels.php

Broadcast::channel('user.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});

Bootstrap.js:

import Echo from 'laravel-echo';

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    enabledTransports: ['ws', 'wss'],
    wsHost: window.location.hostname,
    wssHost: window.location.hostname,
    wsPort: 6001,
    wssPort: 6001,
    forceTLS: true,
    disableStats: true,
    encrypted: true
});

I am getting a good websocket connection but no events arer passing through.

Any idea why I am not receiving anything in my front end please?

0 likes
4 replies
myregistration's avatar

Did you ever figure this out? If so, can you post the solution? Thanks

LaraBABA's avatar

@myregistration The problem I had once with this was the port blocked on the server firewall and a bad ssl path because if you enable wss, you must have an SSL. This is only if you use the web sockets from the laravel package. If you use Pusher, no need. Hope this helps. Not sure if the above problem is similar.

JacobWiley's avatar

I'm having the same problem with the new useEcho method from '@laravel/echo-vue'. Like you, I can see the websocket in the console. Interestingly, my useEchoPresence() code works just fine.

const initPresenceChannel = () => {
        if (presenceChannel.value === false) {

            const { channel } = useEchoPresence('presence-users', [], () => {});
            presenceChannel.value = channel();

            presenceChannel.value.here((users: any[]) => {
                onlineUsers.value = users;
            });
            presenceChannel.value.joining((user: any) => {
                addUser(user);
            });
            presenceChannel.value.leaving((user: any) => {
                removeUser(user);
            });
        }
    };

    const initNotificationsChannel = (user_id: number = 1) => {
        if (notificationsChannel.value === false) {
            const { channel } = useEcho('notifications.' + user_id.toString(), 'App\\Events\\NotificationsEvent', (e) => {
				// THIS EVENT NEVER FIRES
                console.log('----notifications event', e);
            });
            notificationsChannel.value = channel();
        }
    };

Please or to participate in this conversation.