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

Dev0ps's avatar

presence Channel not working

JS

var presenceChannel = pusher.subscribe('presence-onlineusers.'+user);
    presenceChannel.bind('onlineusers', function(data) {
      alert(JSON.stringify(presenceChannel));
    });

Event showing in pusher but not appearing in my page

Channel

Broadcast::channel('onlineusers.{id}', function () {
    return Auth::check();
});

Event

<?php

namespace App\Events;

use App\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class UpdateLiveUser implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $vid;

    public function __construct($vid)
    {
        $this->vid = $vid;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        // return ['onlineusers'];
        return new PresenceChannel('onlineusers.'.$vid);
    }

    public function broadcastAs()
    {
        return 'onlineusers';
    }
      public function broadcastWith()
      {
        return [
        //   'body' => $this->vmsg,
        //   'title' => $this->vname,
        //   'name' => $this->vtitle,
        //   'avatar' => $this->vimg,
        //   'type' => $this->vtype,
          'rid' => \Auth::id()  
        ];
      }
}

Trigger as

event(new \App\Events\UpdateLiveUser($vid));
0 likes
2 replies
Dev0ps's avatar
[{"type":"WebSocketError","error":{"type":"PusherError","data":{"code":null,"message":"user_info supplied to presence subscription is invalid - if supplied it must be a type of hash"}}}]
jayantlz's avatar

@Dev0ps I think this link might help.

Broadcast::channel('notifications.{userId}', function ($user, $userId) {
    if ($user->id == $userId)
        return ['id' => $user->id, 'name' => $user->name]; // Return the user array not true/false if user can access to channel
});
1 like

Please or to participate in this conversation.