Playing
01. Introduction and setup

Transcript

00:00
In this course we're going to set up Sockety in Laravel and look at broadcasting real-time events on public and private channels. Sockety is a real-time web server and we can use this as a direct replacement to services like Pusher which makes it a much cheaper option if you're just getting started or if you have a lower budget. And this integrates really nicely with Laravel's default broadcasting functionality
00:23
so we don't really need to do too much setup within Laravel itself. Sockety is also incredibly fast and it can scale so you might just end up using it instead of a paid service. So let's dive in with a fresh Laravel project and we're going to go ahead and use the command line here to create our Sockety Basics project with the Laravel Installer.
00:46
Okay, so that's all installed. The first thing that we'll do is go ahead and just run php artisan serve just to grab a development server and you can see that in the browser now.
00:56
And if we just head over to our EMV file we are going to be using the database here. So let's switch the connection over here. You of course might be using MySQL which is absolutely fine and let's go ahead and grab the database name so we can create a fresh database as well.
01:11
I'm just going to switch the username around and we're pretty much done. Okay, so I've gone ahead and created the empty database just over here and what we're going to do is just go ahead and run php artisan migrate over here. So let's create out a new tab very quickly and run php artisan migrate
01:30
and as we can see that's not worked. So let's just have a look. Let's just double check this. That should be 5 4 3 2.
01:39
There we go. Okay, so that's done. Okay, so we've got a fresh Laravel app up and running for the purpose of this. We're going to go ahead and use the Laravel Breeze starter kit
01:50
just so we have some authentication in place. The reason that we're going to do that is because as part of this, we're going to look at private channels which require the user to be authenticated. So if you're pushing broadcast events to a specific user on a specific channel
02:06
and you have some kind of condition around that is likely that they're going to be signed in as a user. So let's head over to the Laravel Breeze installation section. Go ahead and grab the composer command to go ahead and install this. While that's doing let's look at what else we need to do.
02:21
We need to run the Breeze install command to publish the controllers. Let's do that. And then we just need to run npm install npm run dev and finally php artisan migrate which we shouldn't need to do because we've already done.
02:33
So let's go ahead and do npm install and npm run dev and we should be good when this is finished. Okay, so that's all finished. If we head back over to the browser here, we should be able to register an account. So let's go ahead and just fill in some details here.
02:49
And now we've done that let's register and there we are over in our dashboard. So for the purpose of this we're not going to be creating anything too useful. We're just going to be within JavaScript listening for these events and dumping them out to the console. What you can then do is integrate this into perhaps view
03:06
or whichever front-end language you're using or whichever front-end framework you're using. So you leave the console open just here so we can go ahead and see that dumped out. Okay, we're all set up the next episode. We're going to set Sockety up and configure it.

Episode summary

Welcome to the course! In this first episode, we kick things off by introducing what we'll be doing: setting up Sockety in a fresh Laravel project to broadcast real-time events, both on public and private channels. Sockety is a great, fast, and affordable alternative to paid services like Pusher, and it integrates nicely with Laravel's built-in broadcasting tools.

We start by spinning up a new Laravel app, walking through the basic installation and getting the development server running. After setting up our database configuration (you can use MySQL or whichever DB you prefer), we migrate the initial tables to make sure everything works.

Next, we install Laravel Breeze. This gives us some quick authentication scaffolding, which we'll need later in the course when working with private channels—private channels require users to be signed in, so this step is important. We go through installing Breeze, running the necessary npm commands, and making sure everything is working by registering a dummy user and logging in.

For the moment, we set up the basics you'd need to receive and listen for broadcast events in JavaScript. Nothing fancy yet, but we’ll be able to see the events dumped to the browser console. Down the line, you can hook this up to your favorite frontend framework (like Vue.js) if you want.

That's our intro and setup done! In the next episode, we'll actually get Sockety up and running, and dive into the real-time fun.

Episode discussion

No comments, yet. Be the first!