Laravel Broadcast Redis Socket io Tutorial
https://www.itsolutionstuff.com/post/laravel-broadcast-redis-socket-io-tutorial-example.html
Today, out leading topic is event broadcasting with redis and socket.io in laravel application. i want to give you very simple example of laravel broadcast using rest and socket io in laravel application. you can send real time chat message using rest socket io and event broadcasting with laravel 6, laravel 7, laravel 8 and laravel 9 application.
Laravel provide event broadcasting topic. event broadcast is a very interesting and it's also difficult to implement with redis and socket.io as specially. but i will give you step by step instruction of how to send real time message with rest and socket io in laravel 6 application.
You need to just follow few step to done this following thing. so let's follow bellow steps and done as real time notification with laravel.

Step 1: Install Laravel 6
First of all, we need to get fresh Laravel 6 version application using bellow command because we are going from scratch, So open your terminal OR command prompt and run bellow command:
Step 2: Install predis
In this step, we need to install predis as bellow command. so let's run following command to install predis in laravel app.
Read Also: Example of unionAll in Query Builder Laravel
Step 3: Create Event
Here, we need to create event for broadcasting. in event file we need to set channel and send message array with key. so, let's run following command for creating event.
app/Events/SendMessage.php
Step 4: Update configuration File
In this step, we need to add set configuration on env file and database configuration file. you you need to set env file with BROADCAST_DRIVER as redis and database configuration and also database redis configuration.
Let's updated files:
.env
config/database.php
Now we need to run migration also.
So, let's run migration.
Step 5: Install Laravel Echo Server
In this step, we need to install laravel-echo-server in your system and in your project. so let's run following command to install laravel-echo-server and init.
Install laravel-echo-server
Init laravel-echo-server
You have to setup your configuration. you can see bellow screenshot:

It will create new file laravel-echo-server.json file as like bellow:
laravel-echo-server.json
Step 6: Install npm, laravel-echo, socket.io-client
Here, we will install npm and also install laravel-echo, socket.io-client. also you need to configuration. so let's run following command:
Now we need to create new file laravel-echo-setup.js file on assets file.
resources/assets/js/laravel-echo-setup.js
Now you need to add on mix file as like bellow:
webpack.mix.js
Now we need to run npm run command:
Step 7: Update View File
Now we need to update our welcome blade file. so you can see our there code as like bellow:
resources/views/welcome.blade.php
Step 8: Call Event
Here, we will create new testing route for call event. so, let's add add following route as bellow:
routes/web.php
Now we are ready to run our example, but make sure following thing to run your project.
You must have to install redis server in your system or server. it not then you can install using following command:
After that you can start laravel echo server as like bellow command:
Now you can run project using following command:
Now you can open bellow URL on your browser:
Now you can fire you event by this url:
Read Also: Laravel 6 Admin Panel Tutorial
You can see result as like bellow screen shot:

You can download code from git: Download Code from Github
I hope it can help you...
Last updated
Was this helpful?