Private Channels not working in Filament project

I have a filament (laravel) project. I’m using filament for whole application. Authentication, roles, permissions everything is handled through filament.

In a filament custom page, I need to use Laravel reverb for real time updates without reloading page.

For it’s setup, I followed the official docs of laravel reverb.

But on client side, I have not used the echo.js generated by php artisan install:broadcasting, instead used
config/filament.php:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> ...
'broadcasting' => [
'echo' => [
'broadcaster' => 'reverb',
'key' => env('VITE_REVERB_APP_KEY'),
'cluster' => env('VITE_REVERB_APP_CLUSTER'),
'wsHost' => env('VITE_REVERB_HOST'),
'wsPort' => env('VITE_REVERB_PORT', 80),
'wssPort' => env('VITE_REVERB_PORT', 443),
'authEndpoint' => '/broadcasting/auth',
'disableStats' => true,
'encrypted' => true,
'forceTLS' => env('VITE_REVERB_SCHEME', 'https') === 'https',
],
],
...
</code>
<code> ... 'broadcasting' => [ 'echo' => [ 'broadcaster' => 'reverb', 'key' => env('VITE_REVERB_APP_KEY'), 'cluster' => env('VITE_REVERB_APP_CLUSTER'), 'wsHost' => env('VITE_REVERB_HOST'), 'wsPort' => env('VITE_REVERB_PORT', 80), 'wssPort' => env('VITE_REVERB_PORT', 443), 'authEndpoint' => '/broadcasting/auth', 'disableStats' => true, 'encrypted' => true, 'forceTLS' => env('VITE_REVERB_SCHEME', 'https') === 'https', ], ], ... </code>
    ...
    'broadcasting' => [
    
            'echo' => [
                'broadcaster' => 'reverb',
                'key' => env('VITE_REVERB_APP_KEY'),
                'cluster' => env('VITE_REVERB_APP_CLUSTER'),
                'wsHost' => env('VITE_REVERB_HOST'),
                'wsPort' => env('VITE_REVERB_PORT', 80),
                'wssPort' => env('VITE_REVERB_PORT', 443),
                'authEndpoint' => '/broadcasting/auth',
                'disableStats' => true,
                'encrypted' => true,
                'forceTLS' => env('VITE_REVERB_SCHEME', 'https') === 'https',
            ],
    
        ],
    ...

Also added Broadcast::routes(['middleware' => [FilamentHttpMiddlewareAuthenticate::class]]); to boot method of AppServiceProvider.php, because without this I was getting 404 not found error on '/broadcasting/auth'.

Now public channels are working without any issue but private channels are not working.

Below is the code of Event NewGroupMessage.php

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?php
namespace AppEvents;
use AppModelsGroupMessage;
use IlluminateBroadcastingChannel;
use IlluminateBroadcastingInteractsWithSockets;
use IlluminateBroadcastingPresenceChannel;
use IlluminateBroadcastingPrivateChannel;
use IlluminateContractsBroadcastingShouldBroadcast;
use IlluminateFoundationEventsDispatchable;
use IlluminateQueueSerializesModels;
class NewGroupMessage implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*/
public function __construct(public GroupMessage $message)
{
//
}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, IlluminateBroadcastingChannel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('new-group-message.' . $this->message->group_id),
new Channel('new-group-message'),
];
}
public function broadcastWith()
{
return [
'id' => $this->message->id,
'created_by_id' => $this->message->created_by_id,
'message' => $this->message->message,
'created_at' => $this->message->created_at,
];
}
}
</code>
<code><?php namespace AppEvents; use AppModelsGroupMessage; use IlluminateBroadcastingChannel; use IlluminateBroadcastingInteractsWithSockets; use IlluminateBroadcastingPresenceChannel; use IlluminateBroadcastingPrivateChannel; use IlluminateContractsBroadcastingShouldBroadcast; use IlluminateFoundationEventsDispatchable; use IlluminateQueueSerializesModels; class NewGroupMessage implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; /** * Create a new event instance. */ public function __construct(public GroupMessage $message) { // } /** * Get the channels the event should broadcast on. * * @return array<int, IlluminateBroadcastingChannel> */ public function broadcastOn(): array { return [ new PrivateChannel('new-group-message.' . $this->message->group_id), new Channel('new-group-message'), ]; } public function broadcastWith() { return [ 'id' => $this->message->id, 'created_by_id' => $this->message->created_by_id, 'message' => $this->message->message, 'created_at' => $this->message->created_at, ]; } } </code>
<?php

namespace AppEvents;

use AppModelsGroupMessage;
use IlluminateBroadcastingChannel;
use IlluminateBroadcastingInteractsWithSockets;
use IlluminateBroadcastingPresenceChannel;
use IlluminateBroadcastingPrivateChannel;
use IlluminateContractsBroadcastingShouldBroadcast;
use IlluminateFoundationEventsDispatchable;
use IlluminateQueueSerializesModels;

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

    /**
     * Create a new event instance.
     */
    public function __construct(public GroupMessage $message)
    {
        //
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return array<int, IlluminateBroadcastingChannel>
     */
    public function broadcastOn(): array
    {
        return [
            new PrivateChannel('new-group-message.' . $this->message->group_id),
            new Channel('new-group-message'),
        ];
    }

    public function broadcastWith()
    {
        return [
            'id' => $this->message->id,
            'created_by_id' => $this->message->created_by_id,
            'message' => $this->message->message,
            'created_at' => $this->message->created_at,
        ];
    }
}

channels.php

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?php
use IlluminateSupportFacadesBroadcast;
Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
Broadcast::channel('new-group-message.{groupId}', function ($user, $groupId) {
return true;
});
</code>
<code><?php use IlluminateSupportFacadesBroadcast; Broadcast::channel('App.Models.User.{id}', function ($user, $id) { return (int) $user->id === (int) $id; }); Broadcast::channel('new-group-message.{groupId}', function ($user, $groupId) { return true; }); </code>
<?php

use IlluminateSupportFacadesBroadcast;

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

Broadcast::channel('new-group-message.{groupId}', function ($user, $groupId) {
    return true;
});

In blade file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><script>
function getMessages() {
window.Echo.private('new-group-message.{{ $groupId }}')
.listen('NewGroupMessage', (e) => {
console.log('new group message private ');
console.log(e);
})
window.Echo.channel('new-group-message')
.listen('NewGroupMessage', (e) => {
console.log('new group message public ');
console.log(e);
})
}
window.addEventListener('load', getMessages);
</script>
</code>
<code><script> function getMessages() { window.Echo.private('new-group-message.{{ $groupId }}') .listen('NewGroupMessage', (e) => { console.log('new group message private '); console.log(e); }) window.Echo.channel('new-group-message') .listen('NewGroupMessage', (e) => { console.log('new group message public '); console.log(e); }) } window.addEventListener('load', getMessages); </script> </code>
<script>
        function getMessages() {
            window.Echo.private('new-group-message.{{ $groupId }}')
                .listen('NewGroupMessage', (e) => {
                    console.log('new group message private ');
                    console.log(e);
                })
            window.Echo.channel('new-group-message')
                .listen('NewGroupMessage', (e) => {
                    console.log('new group message public ');
                    console.log(e);
                })


        }

        window.addEventListener('load', getMessages);
    </script>

Here public channel works fine but private channel doesn’t even subscribe to channel.

Please help, what I’m missing?

I’m using:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Laravel: 11.18.1
Filament: 3.2
Reverb: 1.0
Laravel Echo: 1.16.1
</code>
<code>Laravel: 11.18.1 Filament: 3.2 Reverb: 1.0 Laravel Echo: 1.16.1 </code>
Laravel: 11.18.1
Filament: 3.2
Reverb: 1.0
Laravel Echo: 1.16.1

After trying so many things and reading official docs of Laravel Broadcasting, Laravel Reverb, and Filament, it is now working. Sharing the solution below for other developers facing similar issue:

Either add following lines of code to boot method of
AppServiceProvider.php:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> // other code if any
IlluminateSupportFacadesBroadcast::routes([
'middleware' => [
IlluminateCookieMiddlewareEncryptCookies::class,
IlluminateSessionMiddlewareStartSession::class,
IlluminateSessionMiddlewareAuthenticateSession::class,
IlluminateFoundationHttpMiddlewareVerifyCsrfToken::class,
FilamentHttpMiddlewareAuthenticate::class,
]
]);
require base_path('routes/channels.php');
</code>
<code> // other code if any IlluminateSupportFacadesBroadcast::routes([ 'middleware' => [ IlluminateCookieMiddlewareEncryptCookies::class, IlluminateSessionMiddlewareStartSession::class, IlluminateSessionMiddlewareAuthenticateSession::class, IlluminateFoundationHttpMiddlewareVerifyCsrfToken::class, FilamentHttpMiddlewareAuthenticate::class, ] ]); require base_path('routes/channels.php'); </code>
        // other code if any

        IlluminateSupportFacadesBroadcast::routes([
            'middleware' => [
                IlluminateCookieMiddlewareEncryptCookies::class,
                IlluminateSessionMiddlewareStartSession::class,
                IlluminateSessionMiddlewareAuthenticateSession::class,
                IlluminateFoundationHttpMiddlewareVerifyCsrfToken::class,
                FilamentHttpMiddlewareAuthenticate::class,
            ]
        ]);
        require base_path('routes/channels.php');

Or add following lines of code to bootstrap/app.php:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> ->withBroadcasting(
__DIR__ . '/../routes/channels.php',
[
'middleware' => [
IlluminateCookieMiddlewareEncryptCookies::class,
IlluminateSessionMiddlewareStartSession::class,
IlluminateSessionMiddlewareAuthenticateSession::class,
IlluminateFoundationHttpMiddlewareVerifyCsrfToken::class,
FilamentHttpMiddlewareAuthenticate::class,
]
],
)
</code>
<code> ->withBroadcasting( __DIR__ . '/../routes/channels.php', [ 'middleware' => [ IlluminateCookieMiddlewareEncryptCookies::class, IlluminateSessionMiddlewareStartSession::class, IlluminateSessionMiddlewareAuthenticateSession::class, IlluminateFoundationHttpMiddlewareVerifyCsrfToken::class, FilamentHttpMiddlewareAuthenticate::class, ] ], ) </code>
    ->withBroadcasting(
        __DIR__ . '/../routes/channels.php',
        [
            'middleware' => [
                IlluminateCookieMiddlewareEncryptCookies::class,
                IlluminateSessionMiddlewareStartSession::class,
                IlluminateSessionMiddlewareAuthenticateSession::class,
                IlluminateFoundationHttpMiddlewareVerifyCsrfToken::class,
                FilamentHttpMiddlewareAuthenticate::class,
            ]
        ],
    )

Final bootstrapapp.php will look like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?php
use IlluminateFoundationApplication;
use IlluminateFoundationConfigurationExceptions;
use IlluminateFoundationConfigurationMiddleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__ . '/../routes/web.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
)
->withBroadcasting(
__DIR__ . '/../routes/channels.php',
[
'middleware' => [
IlluminateCookieMiddlewareEncryptCookies::class,
IlluminateSessionMiddlewareStartSession::class,
IlluminateSessionMiddlewareAuthenticateSession::class,
IlluminateFoundationHttpMiddlewareVerifyCsrfToken::class,
FilamentHttpMiddlewareAuthenticate::class,
]
],
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
</code>
<code><?php use IlluminateFoundationApplication; use IlluminateFoundationConfigurationExceptions; use IlluminateFoundationConfigurationMiddleware; return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__ . '/../routes/web.php', commands: __DIR__ . '/../routes/console.php', health: '/up', ) ->withBroadcasting( __DIR__ . '/../routes/channels.php', [ 'middleware' => [ IlluminateCookieMiddlewareEncryptCookies::class, IlluminateSessionMiddlewareStartSession::class, IlluminateSessionMiddlewareAuthenticateSession::class, IlluminateFoundationHttpMiddlewareVerifyCsrfToken::class, FilamentHttpMiddlewareAuthenticate::class, ] ], ) ->withMiddleware(function (Middleware $middleware) { // }) ->withExceptions(function (Exceptions $exceptions) { // })->create(); </code>
<?php

use IlluminateFoundationApplication;
use IlluminateFoundationConfigurationExceptions;
use IlluminateFoundationConfigurationMiddleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__ . '/../routes/web.php',
        commands: __DIR__ . '/../routes/console.php',
        health: '/up',
    )
    ->withBroadcasting(
        __DIR__ . '/../routes/channels.php',
        [
            'middleware' => [
                IlluminateCookieMiddlewareEncryptCookies::class,
                IlluminateSessionMiddlewareStartSession::class,
                IlluminateSessionMiddlewareAuthenticateSession::class,
                IlluminateFoundationHttpMiddlewareVerifyCsrfToken::class,
                FilamentHttpMiddlewareAuthenticate::class,
            ]
        ],
    )
    ->withMiddleware(function (Middleware $middleware) {
        //
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

NOTE: Add above code in one file only. Either in AppServiceProvider or bootstrapapp.php.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật