In a new post to his Medium.com site Adnan Sabanovic shows you how to combine Laravel and Socket.io to create in-application messaging.
Websockets are cool. They are really helpful if you want to show real time activities from your users (or perhaps some queue jobs). Now, if you are afraid of the word “Websockets”, don’t be. I will lay down the instructions on how you can use it and will be around to answer your questions if you need to.
I had this challenge where I needed it to show a list of people who are currently viewing a specific URL in Laravel. So I started thinking. Part of me wanted to do a quick hack (luckily that’s not the strongest side of mine), whilst the other wanted to build something cool, reusable and long-lasting.
While many recommend using the Pusher service, there's a way to replicate it locally using Socket.io and the Laravel Echo Server. He walks you through the process of getting a new Homestead box up and running, installing Redis and installing the Echo Server. After some configuration changes he shows the installation of the Socket.io client and laravel-echo interface. Example code is included showing how to send the broadcast messages and to listen for broadcasted messages.