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

MaverickChan's avatar

Reverb Issue: Echo will not pickup private channel when using Laravel as api server.

bootstrap/app.php

->withBroadcasting(
        __DIR__.'/../routes/channels.php',
        ['prefix' => 'api', 'middleware' => ['api', 'auth:sanctum']],
    )

also, excluded channel.php

->withRouting(
        web: __DIR__.'/../routes/web.php',
        api: __DIR__.'/../routes/api.php',
        commands: __DIR__.'/../routes/console.php',
        // channels: __DIR__.'/../routes/channels.php',
        health: '/up',
    )

BroadcastServiceProvider.php

public function boot(): void
    {
        Broadcast::routes(['middleware' => ['auth:sanctum']]);
        require base_path('routes/channels.php');
    }

channel.php

Broadcast::channel('chat.{id}', function (User $user, int $id) {
    return $user->id === $id;
}, ['guards' => ['sanctum']]);

create event is fine, use dd to check, all passed. when firing the event, reverb debug shows the right info in terminal.

now the problem seems like in the frontend. followed Sanctum instruction of private channel broadcasting.

echo.js added this

authorizer: (channel) => {
        return {
            authorize: (socketId, callback) => {
                axios.post('/api/broadcasting/auth', {  // because added api prefix, the auth route changed
                    socket_id: socketId,
                    channel_name: channel.name
                }, {
                    headers: {
                        'Authorization': `Bearer ${localStorage.getItem('newcrawler_accessToken')}`
                    }
                })
                .then(response => {
                    callback(false, response.data);
                })
                .catch(error => {
                    callback(true, error);
                });
            }
        };
    },

now the problem is , all public channel listen fine. but , private channel cannot be listened, and no error message in console, just show nothing at all looks like Echo has never touched private channel.

Any thoughts?

0 likes
2 replies
MaverickChan's avatar
MaverickChan
OP
Best Answer
Level 47

turns out this is a catch-all route in web.php problem. but i think reverb routes api/broadcasting/auth is not a true api route, it is still a web route, it just has a name api prefix but not given by the api routes. Hope this will be fixed.

Please or to participate in this conversation.