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

spar_x's avatar

Using a different broadcasting middleware for Laravel Nova

I have a bit of a weird situation. I have a Laravel backend that powers a web app but I also use Laravel Nova. Both the web app and Laravel Nova makes use of realtime notifications and laravel broadcasting via laravel-websockets.

My web app uses api/api:auth middleware to authenticate, which itself uses JWT, and Laravel Nova uses normal web authentication.

In order to get both to work I've had to come up with this hacky solution here:

BroadcastServiceProvider

if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === '/broadcasting/auth' && isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], '/nova/') !== false) {
    Broadcast::routes();
} else {
    Broadcast::routes(['middleware' => [
        'api',
        'auth:api',
    ]]);
}

It's not the cleanest and it adds overhead to every single route.. but I couldn't find another way of making it work.

Anyone have any idea on how I could achieve this in a cleaner way?

Many thanks!

0 likes
0 replies

Please or to participate in this conversation.