Problem: Shared Broadcast Channel0:00
I now want to discuss private channels. So I've tweaked our tasks setup just a little bit. No longer are they created sort of in the global space, but they are instead assigned and associated with a Project. So here we have the Project with an ID of 1, maybe for me, for my family. And then we have another Project with an ID of 2, that's maybe for the Miller family. So here's the issue, and we'll go over this structure in a moment. It's very, very simple Laravel 101 type stuff. But anyways, we have an issue. If we add a task, well, the way things are set up currently, even though we added it to the Way family, because we made a broadcast on that generic channel, well, every single list picked up on that. So the Way family added a task that was picked up and posted to the Miller families. Now, that doesn't mean it's being saved to the database. It's the JavaScript side. On the client, we're listening for that pusher message,
Scoping Channels by Project1:27
if we go to our TaskListView component, every single project is opening up that channel. So we're turning the TV knob to that channel, and we're listening. So clearly, any time you add a new Task, every single list is going to pick up on that. That's obviously not what we want, right? So let's see if we can tweak this. What if we, well, to start, we're going to switch to a private channel in a minute. But yeah, to start, you might say, well, we'll be more specific. So we'll say tasks., and then maybe the taskListID. So I could say taskListID. And actually, hold this thought. If you want a quick recap on what I've done, we now have a projects table that just contains the name, and then for our tasks table, every single Task is assigned a Project. Okay, and then in our routes file, if you try to visit a Project, we will fetch or eager load all of the tasks for that Project and load it. And then here's our API. So if you make a GET
Implement Project-Specific Channels2:15
Okay, and then in our routes file, if you try to visit a Project, we will fetch or eager load all of the tasks for that Project and load it. And then here's our API. So if you make a GET request to this endpoint, we'll fetch all the tasks for that Project. And then, of course, if you make a POST request to add a new task to that Project, we will delegate. Pretty simple Laravel 101 stuff. So I think we can continue on. Back in our event, we're now saying the channel is no longer tasks, it's going to be tasks., and then the ID of the Project. And I'm sorry, I called it list ID, I meant project ID. So something like that. All right. Well, if we take that approach, in our task list view component, we need to say here, tasks., and then we'll fetch the list ID. This project.ID. Anyways, does this all make sense? We're now being a little more specific. Don't just turn to all tasks. We only care about the tasks for the
Testing and Security Concern3:05
fetch the list ID. This project.ID. Anyways, does this all make sense? We're now being a little more specific. Don't just turn to all tasks. We only care about the tasks for the project with an ID of one. So now let's give both of these a refresh. And we'll add a wave family task. And if I tab away, you'll notice it does not get added to the Miller family. But let's create a new tab real quick, just to make sure it is working for everyone within this list. So if I come back, you'll see this is here without needing to refresh. But once again, it's not going to be sent to the Miller family. So that's better. So the Miller family will get that. But once again, it doesn't get sent over back to the wave family now. So you might be thinking this is the way to go. However, it's still not very secure. Because think about it. Let's just open up our console here. What if they were to say window.echo on the channel called tasks.1, so they're just
