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

orhdoga's avatar

Laravel Pusher Doesn't Join Private Channel

Hey, there. So I'm using Laravel 5.8, and I have this problem in which my Laravel Echo code doesn't trigger Pusher to join a private channel. When I switch things up to a public channel, everything seems to work fine. This is how my code looks like:

In App\Events\ProfileUpdated:

<?php

namespace App\Events;

use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

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

    public $user;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($user)
    {
        $this->user = $user;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        // return new PrivateChannel('Profile.' . $this->user->id);
        return new PrivateChannel('Profile');
    }
}

In routes\channels.php:

<?php

// Criteria on which a user is allowed to listen to the defined channel
// Broadcast::channel('Profile.{id}', function ($user, $id) {
//     return (int) $user->id === (int) auth()->user()->id;
// });

Broadcast::channel('Profile', function () {
    return true;
});

In UserProfileComponent.vue:

created() {
        // Doesn't join private channel for some reason
        // window.Echo.private('Profile.' + this.authUser.id)
        window.Echo.private('Profile')
            .listen('ProfileUpdated', ({user}) => {
                // Code to be executed
            });
    },

Pusher debug console output:

https://imgur.com/a/0YVCnxi

I hope someone can understand better what is going on! Thanks in advance.

0 likes
4 replies
Punksolid's avatar

Hi @orhdoga, when you use a private channel, first it makes an authentication that will bring a token that will be used on pusher later. Check if that your '/auth' request on the network tab of your browser is not giving you a 404 or another bad status code. That request is done automatically by laravel echo.

orhdoga's avatar

Thank you for your reply. I already checked on this, and I get nothing back in return upon refreshing the page. Also, I must tell you that this problem started occurring after I implemented a language switcher that involves a 'locale' variable that gets checked by the middleware on every request. I don't know if it could have a correlation with my channels.php

For example, I browse to /en/my-profile instead of /my-profile

Sometimes my pusher debug console output changes to:

https://imgur.com/a/TLUBS8Q

Punksolid's avatar
Level 25

well, maybe, so the request to /auth is not happening? maybe as you said, now the request should be happening in /en/auth

orhdoga's avatar

I found the problem; I have a middleware that is responsible for redirecting any request that does not contain the first route segment of '/en'. This interfered with the automatic request to broadcasting/auth that Laravel does to obtain a token when working with private channels (as described in your previous reply). Thank you very much for your hint that led me to the answer.

Please or to participate in this conversation.