Jun 10, 2024
0
Level 1
Laravel Reverb Implementation
I am pretty new with WebSocket, basically I understood that the socket always listen to requests and somehow broadcast to every device? My first ever attempt with websocket is using Laravel Reverb and I've looked several resources in youtube, docs, blogs, and github. It seemed that the way it is implemented as I've seen as of now is as given below.
- Chat Page - Make a POST HTTP request to the controller with header and body
- Chat Controller - handle the POST data and insert it into database
- Chat Controller - Inside the same controller broadcast an event through GotChat Event to notify every event listeners
- GotChat Event - send data (chat_id) through channels route
- Chat Page - listen for the event then trigger GET request to update the data
This is how I do it as of now, I am not sure if I do it right but it works. Now my real doubt is can I handle whatever in the Chat Controller inside the Chat Event so there's no usage of HTTP request.
What is the best way to implement Reverb?
Please or to participate in this conversation.