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

eaglehdr's avatar

Laravel realtime chat with react

I am now exhausted, and as a final resort coming here. i have a management system with laravel and react. both will host separately but right now setup in Laragon, using auth:sanctum for auth, storing token in redux state. I want to create a inbox feature where users within the same company can chat. What i have done so far

  Route::get('/conversations', [MessageController::class, 'conversations']);
  Route::get('/messages/{user}', [MessageController::class, 'index']); //receive message
  Route::post('/messages', [MessageController::class, 'store']); //send message

cors.php

 'paths' => ['api/*', 'broadcasting/auth', 'sanctum/csrf-cookie'],
    'allowed_methods' => ['*'],
    'allowed_origins' => ['*'],
    'allowed_origins_patterns' => [],
    'allowed_headers' => ['*'],
    'exposed_headers' => [],
    'max_age' => 0,
    'supports_credentials' => false,

channels.php

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

in frontend; in my inbox component

but when i send message, it only stores in database and does not send to websocket. i dont know why i did

   authEndpoint: `${import.meta.env.VITE_API_URL_ONLY}/broadcasting/auth`,
                auth: {
                    headers: {
                        Authorization: `Bearer ${token}`,
                        Accept: 'application/json'
                    },
                },

do i need it or not, i dont know, i just blindly followed GPT, and online stuff.

i am constantly getting websocket connection failed with apparently no error.

another issue is with this /broadcasting/auth endpoint. which always go for CORS,

adding it in cors.php throws a bunch of more errors and error trace . but headline is "exception": "Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException",

i tried every AI i could use, it has been two weeks straight.. i cant get websockets to work. every other tutorial showing a basic channel app, or they use react with in the laravel it self. but I dont find my case.

0 likes
1 reply
JussiMannisto's avatar

do i need it or not, i dont know, i just blindly followed GPT, and online stuff.

That's not a winning strategy. If I were in your shoes, I'd create a fresh Laravel project, follow Laravel's official documentation to install Reverb, and test basic messaging. Once you have it running and understand how it works, add it to your main project with the necessary changes.

If you run into an issue, try to pinpoint what is failing, and ask for help if needed. Don't add random online snippets or AI nonsense.

Debugging the most basic use case is easiest. Test public channels first, then authorized channels.

https://laravel.com/docs/11.x/reverb

https://laravel.com/docs/11.x/broadcasting

Please or to participate in this conversation.