Continue …

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.

“Why don’t you just use Pusher?”

Here is the thing.

Laravel comes with Pusher enabled. Even though Pusher seems like a quick “Plug and play” solution (which it is), it comes with limitations. Check out https://pusher.com/pricing

And most of the tutorials trick you with their title of implementing Websockets when in reality they just want to give you Pusher. (And my favorite part is when they say that you can easily switch to socket.io)

“We want to have an unlimited number of connections”

We don’t want to worry about limitations.

Let’s start.

I am using vagrant / homestead.

For this, we will need to read about Event Broadcasting.

Things to note here (so I don’ t have to repeat things):

1. ShouldBroadcast Interface for Events

2. Enabling Broadcast routes and using routes/channels.php to authenticate users

3. Public Channel — Everyone can listen

4. Private Channel — You need to authorize users before they can join a channel

5. Presence Channel — Like Private but you can pass a lot of additional metadata on that channel and get a list of people who have joined the channel.broadcastOn() Event method

Create Your Event