Laravel Echo Server — Private Channels

Dennis Smink
4 min readJun 9, 2018

In my previous article I talked about setting up Laravel Echo, in this article I will show you what private channels actually mean, and why they are very useful. I recommend you to read my previous article about this if you have not yet, or still need to learn about this whole topic.

Private channels allow you to broadcast pieces of data, that should only be visible to a specific user, or group. For example, if you have a team with users in this, you will only want to have a channel that allows the team members to join that channel and listen to events.

In our previous code, we were running this piece of code:

window.Echo.channel('test-event')
.listen('ExampleEvent', (e) => {
console.log(e);
});

This is cool, but what if I want to broadcast to some piece of data that has information for only the designated user? Here’s when private channels come in. This will require you to have authentication, lets whip up a quick demo.

First, start by creating authentication in your Laravel app (you don’t have to do this, if you have a full app running with authentication from Laravel)

$ php artisan make:auth

Migrate your database (setup your database in your .env file), and register a account on the register page that has…

--

--