laravel broadcasting Broadcasting in private chanel not working i use laravel echo

783 Views Asked by At

event is:

public $chat ;
public function __construct($chat)
{
        $this->chat = $chat;
}
 public function broadcastOn()
{
    //        return new Channel('recieve-chat');
    return new PrivateChannel('recieve-chat' );
}

routes/channels.php is:

Broadcast::channel('recieve-chat', function ($user ) {
        return true;
//    return $user->id === $reciever_id;
});

in blade file:

<script>
    window.addEventListener('DOMContentLoaded' , function () {
         Echo.private('recieve-chat')
                .listen('ChatBroad', (e) => {
                    window.livewire.emit('recieve:' + e.chat.bid_id , e.chat);
                    $(chatScrollDown('.chat'+ e.chat.bid_id ));
                });
        });

</script>

broadcast Channel work properly. but in PrivateChannel is not working. and in console not showing any error

i use laravel echo and pusher

1

There are 1 best solutions below

0
On

in App\Providers\BroadcastServiceProvider.php

public function boot()
{
    Broadcast::routes();

    require base_path('routes/channels.php');
}

must like the code. in Broadcast::routes() we dont need any middleware.