{"id":2395,"date":"2024-05-21T12:51:10","date_gmt":"2024-05-21T12:51:10","guid":{"rendered":"https:\/\/kanhasoft.com\/blog\/?p=2395"},"modified":"2026-02-11T05:12:15","modified_gmt":"2026-02-11T05:12:15","slug":"real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial","status":"publish","type":"post","link":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/","title":{"rendered":"Real-Time Web Applications with Laravel WebSockets: A Step-by-Step Tutorial"},"content":{"rendered":"<h2><span style=\"font-weight: 400;\">Overview of Real-Time Web Applications<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Real-time web applications are a basic component of advanced web development. These applications allow for immediate data trade between the server and clients, making a consistent and interactive client experience. There&#8217;s a developing request for quick back-and-forth communication, as appeared by the popularity of live chat, collaborative devices, and real-time upgrades. <\/span><a href=\"https:\/\/kanhasoft.com\/laravel-application-development.html\"><span style=\"font-weight: 400;\">Laravel web app development<\/span><\/a><span style=\"font-weight: 400;\"> excels in creating such dynamic applications, making real-time interactions efficient and responsive.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Real-time web applications win by keeping clients locked in and filled with the most recent data, killing the requirement for steady refreshing. Real-time features can significantly improve the client experience by making intelligence more dynamic and responsive.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Introduction to Laravel WebSockets<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Unlike traditional HTTP, which requires back-and-forth demands and reactions, WebSockets build up a steady two-way association between client and server. This full-duplex communication, accomplished over a single TCP association, makes WebSockets perfect for real-time applications that depend on ceaseless data flow. In the realm of <\/span><a href=\"https:\/\/kanhasoft.com\/laravel-application-development.html\"><span style=\"font-weight: 400;\">Laravel web app development<\/span><\/a><span style=\"font-weight: 400;\">, integrating WebSockets offers a powerful way to enhance real-time functionality.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you&#8217;re building a Laravel application and need to include real-time functionality, the &#8220;beyondcode\/laravel-websockets&#8221; package gives a vigorous and user-friendly way to actualize WebSockets specifically inside your Laravel system. This kills the require to depend on outside services like Pusher.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">By leveraging Laravel WebSockets, developers can make adaptable and productive real-time web applications with ease. This tutorial will direct you through the handle of setting up Laravel Web Sockets and building a real-time chat application step by step.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Setting Up Laravel for Real-Time Applications<\/span><\/h2>\n<h3><span style=\"font-weight: 400;\">Installing Laravel<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">To begin with Laravel, you must install it via Composer. If you do not have Composer installed, you can download it from the <\/span><a href=\"http:\/\/getcomposer.org\" rel=\"nofollow\"><span style=\"font-weight: 400;\">getcomposer.org <\/span><\/a><span style=\"font-weight: 400;\">website. Once Composer is installed, open your terminal and run the taking after the command to make a new Laravel project:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>composer create-project --prefer-dist laravel\/laravel realtime-chat\r\n<\/code><\/pre>\n<p><span style=\"font-weight: 400;\">This command will make an unused Laravel project in a directory named realtime-chat. Explore this catalog to continue with the setup:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>cd realtime-chat\r\n<\/code><\/pre>\n<h3><span style=\"font-weight: 400;\">Configuring Environment for WebSockets<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Before we can begin utilizing Laravel Web Sockets, we need to arrange our environment. Open the &#8216;.env&#8217; record in your Laravel extend and make sure the taking after settings are configured:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>APP_NAME=Laravel\r\nAPP_ENV=local\r\nAPP_KEY=base64:...\r\nAPP_DEBUG=true\r\nAPP_URL=http:\/\/localhost\r\n\r\nBROADCAST_DRIVER=pusher\r\nCACHE_DRIVER=file\r\nQUEUE_CONNECTION=sync\r\nSESSION_DRIVER=file\r\nSESSION_LIFETIME=120\r\n\r\nPUSHER_APP_ID=local\r\nPUSHER_APP_KEY=local\r\nPUSHER_APP_SECRET=local\r\nPUSHER_APP_CLUSTER=mt1\r\n<\/code><\/pre>\n<p><span style=\"font-weight: 400;\">These settings allow Laravel to utilize the Pusher driver for broadcasting occasions. Indeed even though we&#8217;ll be utilizing Laravel Web Sockets, we can still utilize the Pusher driver for local development.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Next, install the required packages for Laravel WebSockets:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>composer require beyondcode\/laravel-websockets pusher\/pusher-php-server<\/code><\/pre>\n<\/div>\n<p class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><span style=\"font-weight: 400;\">After installing the packages, publish the WebSockets setup record by running:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>php artisan vendor:publish --provider=\"BeyondCode\\LaravelWebSockets\\WebSocketsServiceProvider\" --tag=\"config\"<\/code><\/pre>\n<\/div>\n<p><span style=\"font-weight: 400;\">This command will make a websockets.php setup record in the config directory.<\/span><\/p>\n<p><a href=\"https:\/\/kanhasoft.com\/contact-us.html\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/kanhasoft.com\/blog\/wp-content\/uploads\/2023\/11\/Get-Your-Developer-On-Board-Today.gif\" alt=\"Risk-Free Trial Get Your Developer On Board\" width=\"1584\" height=\"396\" class=\"aligncenter size-full wp-image-2077\" \/><\/a><\/p>\n<p class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code><\/code><\/p>\n<h2><span style=\"font-weight: 400;\">Understanding Laravel WebSockets<\/span><\/h2>\n<h3><span style=\"font-weight: 400;\">What are Laravel WebSockets?<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Bring real-time functionality to your Laravel app with Laravel WebSockets. This bundle offers a built-in WebSocket server, dispensing with the requirements for outside administrations like Pusher. It integrates seamlessly with Laravel&#8217;s broadcasting system, making WebSocket integration straightforward, which is a significant advantage in<\/span><a href=\"https:\/\/kanhasoft.com\/laravel-application-development.html\"><span style=\"font-weight: 400;\"> Laravel web app development. <\/span><\/a><\/p>\n<p><span style=\"font-weight: 400;\">By <\/span><span style=\"font-weight: 400;\">empowering a continually open association between client and server, WebSockets encourage the continuous stream of information. This advantage makes them culminate for applications requesting real-time upgrades, like chat apps, live notices, and collaborative apparatuses.<\/span><\/p>\n<\/div>\n<div class=\"hcb_wrap\">\n<p><span style=\"color: #000000; font-family: Poppins, sans-serif; font-size: 24px;\">How Laravel WebSockets Work<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Laravel WebSockets enables real-time communication between your application and clients. It fulfills this by setting up a WebSocket server that clients can interface to. Whenever an event is broadcasted within Laravel, the WebSocket server actively sends that event to all connected clients. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s<\/span><span style=\"font-weight: 400;\">\u00a0explore how WebSockets creates a real-time experience in Laravel applications:<\/span><\/p>\n<ul>\n<li>Making the Connection: The user&#8217;s browser (client) opens a special communication channel with the server using WebSockets.<\/li>\n<li>Broadcasting Updates: When something happens in the application, Laravel triggers an event and sends it out using a broadcasting service (like Pusher in this example).<\/li>\n<li><span style=\"font-weight: 400;\">Server Sends Update: The Laravel WebSocket server gets the event and pushes it out to all connected clients.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Clients Receive Update: The clients&#8217; browsers receive the update and can immediately refresh their screens to reflect the new information.<\/span><\/li>\n<\/ul>\n<ul><\/ul>\n<p class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code><\/code><\/p>\n<h2><span style=\"font-weight: 400;\">Building a Real-Time Chat Application<\/span><\/h2>\n<h3><span style=\"font-weight: 400;\">Creating a Basic Laravel Application<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">To illustrate the control of Laravel Web Sockets, we&#8217;ll construct a basic real-time chat application. To begin with, we are required to set up our Laravel application with the vital models, sees, and controllers. <\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Setting<\/span>\u00a0Up Model<\/h3>\n<p><span style=\"font-weight: 400;\">Create a Message demonstration to represent chat messages. Run the following command to produce the show and relocation record:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>php artisan make:model Message -m<\/code><\/pre>\n<\/div>\n<div class=\"hcb_wrap\">\n<p class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><span style=\"font-weight: 400;\">Open the created movement record in the &#8216;database\/migrations&#8217; registry and characterize the pattern for the &#8216;messages&#8217; table:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>Schema::create('messages', function (Blueprint $table) {\r\n    $table-&gt;id();\r\n    $table-&gt;string('username');\r\n    $table-&gt;text('message');\r\n    $table-&gt;timestamps();\r\n});<\/code><\/pre>\n<p><span style=\"font-weight: 400;\">Run the migration to create the &#8216;messages&#8217; table:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>php artisan migrate<\/code><\/pre>\n<h3><span style=\"font-weight: 400;\">Setting Up Controllers<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Next, create a &#8216;ChatController&#8217; to handle chat-related logic. Run the following command to generate the controller:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>php artisan make:controller ChatController<\/code><\/pre>\n<\/div>\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code><\/code><\/pre>\n<p class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><span style=\"font-weight: 400;\">Open the &#8216;ChatController&#8217; and add methods to handle message retrieval and creation<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>namespace App\\Http\\Controllers;\r\n\r\nuse App\\Models\\Message;\r\nuse Illuminate\\Http\\Request;\r\n\r\nclass ChatController extends Controller\r\n{\r\n    public function index()\r\n    {\r\n        return view('chat');\r\n    }\r\n\r\n    public function fetchMessages()\r\n    {\r\n        return Message::all();\r\n    }\r\n\r\n    public function sendMessage(Request $request)\r\n    {\r\n        $message = Message::create([\r\n            'username' =&gt; $request-&gt;username,\r\n            'message' =&gt; $request-&gt;message\r\n        ]);\r\n\r\n        broadcast(new MessageSent($message))-&gt;toOthers();\r\n\r\n        return ['status' =&gt; 'Message Sent!'];\r\n    }\r\n}\r\n<\/code><\/pre>\n<h3><span style=\"font-weight: 400;\">Setting Up Views<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Make a &#8216;chat.blade.php&#8217; see in the &#8216;resources\/views&#8217; catalog to show the chat interface:<\/span><code><\/code><\/p>\n<div class=\"container\">\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-html\" data-lang=\"HTML\"><code>&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;Laravel WebSockets Chat&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;meta name=\"csrf-token\" content=\"{{ csrf_token() }}\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;link rel=\"stylesheet\" href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/bootstrap\/4.5.2\/css\/bootstrap.min.css\"&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;div class=\"container\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;div id=\"app\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;chat-component&gt;&lt;\/chat-component&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/div&gt;\r\n\u00a0\u00a0\u00a0&lt;script src=\"{{ mix('js\/app.js') }}\"&gt;&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<\/div>\n<p><span style=\"font-weight: 400;\">Next, create a Vue component for the chat interface. Create a &#8216;ChatComponent.vue&#8217; file in the &#8216;resources\/js\/components&#8217; directory:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Vue<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>&lt;template&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;div class=\"chat-container\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;ul class=\"list-group\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;li class=\"list-group-item\" v-for=\"message in messages\" :key=\"message.id\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;strong&gt;{{ message.username }}&lt;\/strong&gt;: {{ message.message }}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/li&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/ul&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;input v-model=\"newMessage\" @keyup.enter=\"sendMessage\" class=\"form-control\" placeholder=\"Type a message...\"&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/div&gt;\r\n&lt;\/template&gt;\r\n&lt;script&gt;\r\nexport default {\r\n\u00a0\u00a0\u00a0\u00a0data() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0messages: [],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0newMessage: ''\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0},\r\n\u00a0\u00a0\u00a0\u00a0mounted() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.fetchMessages();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Echo.channel('chat')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.listen('MessageSent', (e) =&gt; {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.messages.push(e.message);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\u00a0\u00a0\u00a0\u00a0},\r\n\u00a0\u00a0\u00a0\u00a0methods: {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0fetchMessages() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0axios.get('\/messages').then(response =&gt; {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.messages = response.data;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sendMessage() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0axios.post('\/messages', {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0username: 'User',\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0message: this.newMessage\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}).then(response =&gt; {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.newMessage = '';\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0}\r\n}\r\n&lt;\/script&gt;\r\n&lt;style scoped&gt;\r\n.chat-container {\r\n\u00a0\u00a0\u00a0\u00a0max-width: 600px;\r\n\u00a0\u00a0\u00a0\u00a0margin: 0 auto;\r\n\u00a0\u00a0\u00a0\u00a0margin-top: 50px;\r\n}\r\n&lt;\/style&gt;<\/code><\/pre>\n<\/div>\n<p><span style=\"font-weight: 400;\">Finally, upgrade &#8216;resources\/js\/app.js&#8217; to enroll the Vue component:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>require('.\/bootstrap');\r\nwindow.Vue = require('vue');\r\nVue.component('chat-component', require('.\/components\/ChatComponent.vue').default);\r\nconst app = new Vue({\r\n\u00a0\u00a0\u00a0\u00a0el: '#app'\r\n});\r\n<a href=\"https:\/\/kanhasoft.com\/contact-us.html\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/kanhasoft.com\/blog\/wp-content\/uploads\/2023\/11\/Risk-Free-Trial-Get-Your-Developer-On-Board.gif\" alt=\"Risk-Free Trial Get Your Developer On Board\" width=\"1584\" height=\"396\" class=\"aligncenter size-full wp-image-2076\" \/><\/a><span style=\"background-color: #ffffff; color: #000000; font-family: Poppins, sans-serif; font-size: 32px;\">Setting Up Laravel WebSockets<\/span><\/code><\/pre>\n<\/div>\n<p><b>Installing the Laravel WebSockets Package<\/b><\/p>\n<p><span style=\"font-weight: 400;\">We have already installed the &#8216;beyondcode\/laravel-websockets&#8217; package. Next, we need to configure the WebSocket server.<\/span><\/p>\n<p><b>Configuring WebSockets Server<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Open the &#8216;config\/websockets.php&#8217; file and update the configuration as needed. For local development, the default settings should suffice.<\/span><\/p>\n<p><b>Running the WebSocket Server<\/b><\/p>\n<p><span style=\"font-weight: 400;\">To start the WebSocket server, run the following command:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code><span style=\"font-weight: 400;\">php artisan websockets:serve<\/span><\/code><\/pre>\n<\/div>\n<p><span style=\"font-weight: 400;\">The WebSocket server will begin running on &#8216;http:\/\/127.0.0.1:6001&#8217; by default. You can presently interface to this server from your application.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Integrating WebSockets into the Chat Application<\/span><\/h3>\n<h3><span style=\"font-weight: 400;\">Broadcasting Events in Laravel<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">We need to create an event for broadcasting messages. Run the following command to generate the &#8216;MessageSent&#8217; event:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code><span style=\"font-weight: 400;\">php artisan make:event MessageSent<\/span><\/code><\/pre>\n<\/div>\n<p><span style=\"font-weight: 400;\">Open the &#8216;MessageSent&#8217; event class and update it as follows:<\/span><\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>namespace App\\Events;\r\nuse App\\Models\\Message;\r\nuse Illuminate\\Broadcasting\\Channel;\r\nuse Illuminate\\Broadcasting\\InteractsWithSockets;\r\nuse Illuminate\\Broadcasting\\PresenceChannel;\r\nuse Illuminate\\Broadcasting\\PrivateChannel;\r\nuse Illuminate\\Contracts\\Broadcasting\\ShouldBroadcast;\r\nuse Illuminate\\Foundation\\Events\\Dispatchable;\r\nuse Illuminate\\Queue\\SerializesModels;\r\nclass MessageSent implements ShouldBroadcast\r\n{\r\nuse Dispatchable, InteractsWithSockets, SerializesModels;\r\n\u00a0\u00a0\u00a0\u00a0public $message;\r\n\u00a0\u00a0\u00a0\u00a0public function __construct(Message $message)\r\n\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$this-&gt;message = $message;\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0public function broadcastOn()\r\n\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return new Channel('chat');\r\n\u00a0\u00a0\u00a0\u00a0}\r\n}\r\nUpdate the 'ChatController' to broadcast the event when a new message is sent:\r\nphp\r\nuse App\\Events\\MessageSent;\r\n\/\/ ...\r\npublic function sendMessage(Request $request)\r\n{\r\n\u00a0\u00a0\u00a0\u00a0$message = Message::create([\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'username' =&gt; $request-&gt;username,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'message' =&gt; $request-&gt;message\r\n\u00a0\u00a0\u00a0\u00a0]);\r\n\u00a0\u00a0\u00a0\u00a0broadcast(new MessageSent($message))-&gt;toOthers();\r\n\u00a0\u00a0\u00a0\u00a0return ['status' =&gt; 'Message Sent!'];\r\n}<\/code><\/pre>\n<\/div>\n<h3><span style=\"font-weight: 400;\">Listening for Events on the Frontend<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">We have already set up the frontend to listen for the &#8216;MessageSent&#8217; event in the &#8216;ChatComponent.vue&#8217; file using Laravel Echo.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Enhancing Real-Time Capabilities<\/span><\/h2>\n<h3><span style=\"font-weight: 400;\">Scaling Laravel WebSockets<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">As your application grows, you may need to scale your WebSocket server to handle increased traffic. Here are a few best tips for scaling WebSocket applications:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use Redis: Redis can be utilized to store the state of your WebSocket connections and disseminate messages over numerous WebSocket servers. Install Redis and arrange it in your Laravel application by upgrading the &#8216;.env&#8217; file:<\/span><\/li>\n<\/ul>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-plain\" data-lang=\"Plain Text\"><code>BROADCAST_DRIVER=redis\r\nCACHE_DRIVER=redis\r\nQUEUE_CONNECTION=redis\r\nSESSION_DRIVER=redis<\/code><\/pre>\n<\/div>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Load Adjusting: Utilize a load balancer to convey approaching WebSocket connections over different servers. This guarantees that no single server is overpowered with as well numerous connections.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Horizontal Scaling: Include more WebSocket servers to handle expanded activity. Each server can run an instance of the WebSocket server and share the load.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Security Considerations<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Guaranteeing the security of your WebSocket connections is vital to ensure your application and clients. Here are a few techniques for securing WebSockets:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Secure WebSocket (WSS): Utilize WSS (WebSocket Secure) to encrypt the information transmitted between the client and server. This anticipates man-in-the-middle assaults and listening in. Get an SSL certificate and design your WebSocket server to utilize WSS.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Authentication and Authorization: Execute authentication and authorization components to guarantee that only authorized clients can interface with your WebSocket server. Laravel gives built-in support for client verification, which can be expanded to WebSockets.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Rate Restricting: Execute rate limiting to avoid mishandling of your WebSocket server. This can offer assistance in moderate denial-of-service (DoS) assaults and guarantee that your server remains responsive.<\/span><\/li>\n<\/ul>\n<p><a href=\"https:\/\/kanhasoft.com\/contact-us.html\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/kanhasoft.com\/blog\/wp-content\/uploads\/2023\/11\/Hire-Remote-Developers.gif\" alt=\"Hire Remote Developers\" width=\"1584\" height=\"396\" class=\"aligncenter size-full wp-image-2075\" \/><\/a><\/p>\n<h2><span style=\"font-weight: 400;\">Testing and Deployment<\/span><\/h2>\n<h3><span style=\"font-weight: 400;\">Testing Real-Time Features<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Testing real-time features can be challenging, but it&#8217;s fundamental to guarantee that your application capacities are accurate under different conditions. Here are some strategies for testing WebSocket functionality:<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Unit Tests: Write unit tests for your WebSocket event handlers and listeners. Use Laravel&#8217;s testing tools to recreate WebSocket connections and confirm that occasions are broadcasted correctly.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Integration Tests: Perform integration tests to guarantee that all parts of your application work together as anticipated. Test the total stream from sending a message to accepting it on the client side.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Load Testing: Utilize load testing tools to recreate high traffic and guarantee that your WebSocket server can handle the load. Tools like Apache JMeter and Gatling can offer assistance when you perform load tests.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Deploying a Real-Time Laravel Application<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Deploying a real-time Laravel application requires careful preparation to ensure smooth operation. Here are the steps to deploy your application:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Prepare Your Server: Ensure that your server meets the requirements for running a Laravel application and WebSocket server. Install necessary software like PHP, Composer, and Nginx.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Deploy the Code: Utilize form control devices like Git to send your code to the server. Set up a sending pipeline to automate the arrangement process.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Configure the WebSocket Server: Update the WebSocket server configuration for your production environment. Ensure that the server is configured to use WSS and is properly scaled.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Monitor and Maintain: Set up observing tools to keep track of your WebSocket server&#8217;s execution. Utilize logging and alerting tools to identify and react to issues promptly.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">This tutorial secured the essentials of real-time web applications and how to construct them utilizing Laravel Web Sockets. We&#8217;ve walked through setting up a Laravel project, arranging WebSockets, and building a real-time chat application. We&#8217;ve also examined best practices for scaling, securing, testing, and conveying WebSocket applications.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you&#8217;re looking for proficient help with <a href=\"https:\/\/kanhasoft.com\/blog\/enterprise-web-applications-with-laravel-a-step-by-step-guide\/\">Laravel web app development<\/a>, consider reaching a <a href=\"https:\/\/kanhasoft.com\/kanhasoft-CRM.html\">Kanhasoft<\/a>-leading <\/span><a href=\"http:\/\/kanhasoft.com\"><span style=\"font-weight: 400;\">Laravel web application development company<\/span><\/a><span style=\"font-weight: 400;\">. Our specialists will offer assistance to you to construct strong and versatile real-time web applications tailored to your needs. Contact <a href=\"https:\/\/kanhasoft.com\/qa-testing.html\">Kanhasoft<\/a> today to get the benefits of our <\/span><a href=\"https:\/\/kanhasoft.com\/laravel-application-development.html\"><span style=\"font-weight: 400;\">laravel web app development service<\/span><\/a><span style=\"font-weight: 400;\"> for your other project.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">FAQ\u2019s<\/span><\/h2>\n<h2><strong style=\"color: #888888; font-family: Roboto, sans-serif; font-size: 16px;\">1. What are Real-Time Web Applications?<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Real-time web applications allow for consistent information exchange between a server and clients, empowering an intelligently and up-to-date client involvement. Features like live chat and stock tickers are prime examples.<\/span><\/p>\n<p><strong>2. Why utilize Laravel WebSockets?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Laravel WebSockets is a package that offers a built-in WebSocket server, dispensing with the requirement for outside services like Pusher. It consistently coordinates with Laravel&#8217;s broadcasting system, rearranging WebSocket integration for Laravel web development.<\/span><\/p>\n<p><strong>3. How do Laravel WebSockets work?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Laravel WebSockets establishes a WebSocket server that clients can connect to. When an event is broadcasted within Laravel, the WebSocket server actively sends that event to all connected clients. This continuous flow of information keeps users updated in real time.<\/span><\/p>\n<p><strong>4. What are the benefits of utilizing Laravel WebSockets?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Laravel WebSockets enables developers to make adaptable and proficient real-time web applications with ease. It streamlines WebSocket integration and leverages Laravel&#8217;s broadcasting system for a smooth improvement experience.<\/span><\/p>\n<p><strong>5. How to Construct a Real-Time Chat Application with Laravel WebSockets?<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Building a real-time chat application with Laravel WebSockets includes setting up a Laravel project, introducing essential packages, arranging WebSockets, and making a chat interface with frontend and backend components that utilize broadcasting occasions.<\/span><\/p>\n<p><a href=\"https:\/\/kanhasoft.com\/contact-us.html\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/kanhasoft.com\/blog\/wp-content\/uploads\/2023\/11\/Hire-Remote-Developer-with-No-Risk.gif\" alt=\"Hire Remote Developer with No Risk\" width=\"1584\" height=\"396\" class=\"aligncenter size-full wp-image-2074\" \/><\/a><\/p>\n<\/div>\n<p><code><\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code><\/code><\/p>\n<\/div>\n<p class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code><\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Overview of Real-Time Web Applications Real-time web applications are a basic component of advanced web development. These applications allow for immediate data trade between the server and clients, making a consistent and interactive client experience. There&#8217;s a developing request for quick back-and-forth communication, as appeared by the popularity of live <a href=\"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/\" class=\"more-link\">Read More<\/a><\/p>\n","protected":false},"author":3,"featured_media":2410,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-2395","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel-web-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Real-Time Web Applications with Laravel WebSockets: A Tutorial<\/title>\n<meta name=\"description\" content=\"Build real-time web apps with Laravel WebSockets. Follow this guide for easy setup, configuration, and implementation in your projects.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Real-Time Web Applications with Laravel WebSockets: A Tutorial\" \/>\n<meta property=\"og:description\" content=\"Build real-time web apps with Laravel WebSockets. Follow this guide for easy setup, configuration, and implementation in your projects.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/kanhasoft\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-21T12:51:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-11T05:12:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/kanhasoft.com\/blog\/wp-content\/uploads\/2024\/05\/Real-Time-Web-Applications-with-Laravel-WebSockets-A-Step-by-Step-Tutorial.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2000\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Manoj Bhuva\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@kanhasoft\" \/>\n<meta name=\"twitter:site\" content=\"@kanhasoft\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Manoj Bhuva\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\\\/\"},\"author\":{\"name\":\"Manoj Bhuva\",\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/#\\\/schema\\\/person\\\/037907a7ce62ee1ceed7a91652b16122\"},\"headline\":\"Real-Time Web Applications with Laravel WebSockets: A Step-by-Step Tutorial\",\"datePublished\":\"2024-05-21T12:51:10+00:00\",\"dateModified\":\"2026-02-11T05:12:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\\\/\"},\"wordCount\":1778,\"publisher\":{\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/Real-Time-Web-Applications-with-Laravel-WebSockets-A-Step-by-Step-Tutorial.png\",\"articleSection\":[\"Laravel web development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\\\/\",\"url\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\\\/\",\"name\":\"Real-Time Web Applications with Laravel WebSockets: A Tutorial\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/Real-Time-Web-Applications-with-Laravel-WebSockets-A-Step-by-Step-Tutorial.png\",\"datePublished\":\"2024-05-21T12:51:10+00:00\",\"dateModified\":\"2026-02-11T05:12:15+00:00\",\"description\":\"Build real-time web apps with Laravel WebSockets. Follow this guide for easy setup, configuration, and implementation in your projects.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\\\/#primaryimage\",\"url\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/Real-Time-Web-Applications-with-Laravel-WebSockets-A-Step-by-Step-Tutorial.png\",\"contentUrl\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/Real-Time-Web-Applications-with-Laravel-WebSockets-A-Step-by-Step-Tutorial.png\",\"width\":2000,\"height\":600,\"caption\":\"Real-Time-Web-Applications-with-Laravel-WebSockets-A-Step-by-Step-Tutorial\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Real-Time Web Applications with Laravel WebSockets: A Step-by-Step Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/\",\"name\":\"\",\"description\":\"Web and Mobile Application Development Agency\",\"publisher\":{\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/#organization\",\"name\":\"Kanhasoft\",\"url\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"http:\\\/\\\/192.168.1.31:890\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/cropped-cropped-Kahnasoft-Web-and-mobile-app-development-1.png\",\"contentUrl\":\"http:\\\/\\\/192.168.1.31:890\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/cropped-cropped-Kahnasoft-Web-and-mobile-app-development-1.png\",\"width\":239,\"height\":56,\"caption\":\"Kanhasoft\"},\"image\":{\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/kanhasoft\",\"https:\\\/\\\/x.com\\\/kanhasoft\",\"https:\\\/\\\/www.instagram.com\\\/kanhasoft\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/kanhasoft\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/kanhasoft\\\/_created\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/#\\\/schema\\\/person\\\/037907a7ce62ee1ceed7a91652b16122\",\"name\":\"Manoj Bhuva\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/675e142db3f0e3e42ef6c7f7a13c6f72ac33412f2d0096e342e8033f8388238a?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/675e142db3f0e3e42ef6c7f7a13c6f72ac33412f2d0096e342e8033f8388238a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/675e142db3f0e3e42ef6c7f7a13c6f72ac33412f2d0096e342e8033f8388238a?s=96&d=mm&r=g\",\"caption\":\"Manoj Bhuva\"},\"sameAs\":[\"https:\\\/\\\/kanhasoft.com\\\/\"],\"url\":\"https:\\\/\\\/kanhasoft.com\\\/blog\\\/author\\\/ceo\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Real-Time Web Applications with Laravel WebSockets: A Tutorial","description":"Build real-time web apps with Laravel WebSockets. Follow this guide for easy setup, configuration, and implementation in your projects.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Real-Time Web Applications with Laravel WebSockets: A Tutorial","og_description":"Build real-time web apps with Laravel WebSockets. Follow this guide for easy setup, configuration, and implementation in your projects.","og_url":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/","article_publisher":"https:\/\/www.facebook.com\/kanhasoft","article_published_time":"2024-05-21T12:51:10+00:00","article_modified_time":"2026-02-11T05:12:15+00:00","og_image":[{"width":2000,"height":600,"url":"https:\/\/kanhasoft.com\/blog\/wp-content\/uploads\/2024\/05\/Real-Time-Web-Applications-with-Laravel-WebSockets-A-Step-by-Step-Tutorial.png","type":"image\/png"}],"author":"Manoj Bhuva","twitter_card":"summary_large_image","twitter_creator":"@kanhasoft","twitter_site":"@kanhasoft","twitter_misc":{"Written by":"Manoj Bhuva","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/#article","isPartOf":{"@id":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/"},"author":{"name":"Manoj Bhuva","@id":"https:\/\/kanhasoft.com\/blog\/#\/schema\/person\/037907a7ce62ee1ceed7a91652b16122"},"headline":"Real-Time Web Applications with Laravel WebSockets: A Step-by-Step Tutorial","datePublished":"2024-05-21T12:51:10+00:00","dateModified":"2026-02-11T05:12:15+00:00","mainEntityOfPage":{"@id":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/"},"wordCount":1778,"publisher":{"@id":"https:\/\/kanhasoft.com\/blog\/#organization"},"image":{"@id":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/kanhasoft.com\/blog\/wp-content\/uploads\/2024\/05\/Real-Time-Web-Applications-with-Laravel-WebSockets-A-Step-by-Step-Tutorial.png","articleSection":["Laravel web development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/","url":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/","name":"Real-Time Web Applications with Laravel WebSockets: A Tutorial","isPartOf":{"@id":"https:\/\/kanhasoft.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/kanhasoft.com\/blog\/wp-content\/uploads\/2024\/05\/Real-Time-Web-Applications-with-Laravel-WebSockets-A-Step-by-Step-Tutorial.png","datePublished":"2024-05-21T12:51:10+00:00","dateModified":"2026-02-11T05:12:15+00:00","description":"Build real-time web apps with Laravel WebSockets. Follow this guide for easy setup, configuration, and implementation in your projects.","breadcrumb":{"@id":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/#primaryimage","url":"https:\/\/kanhasoft.com\/blog\/wp-content\/uploads\/2024\/05\/Real-Time-Web-Applications-with-Laravel-WebSockets-A-Step-by-Step-Tutorial.png","contentUrl":"https:\/\/kanhasoft.com\/blog\/wp-content\/uploads\/2024\/05\/Real-Time-Web-Applications-with-Laravel-WebSockets-A-Step-by-Step-Tutorial.png","width":2000,"height":600,"caption":"Real-Time-Web-Applications-with-Laravel-WebSockets-A-Step-by-Step-Tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/kanhasoft.com\/blog\/real-time-web-applications-with-laravel-websockets-a-step-by-step-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kanhasoft.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Real-Time Web Applications with Laravel WebSockets: A Step-by-Step Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/kanhasoft.com\/blog\/#website","url":"https:\/\/kanhasoft.com\/blog\/","name":"","description":"Web and Mobile Application Development Agency","publisher":{"@id":"https:\/\/kanhasoft.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kanhasoft.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/kanhasoft.com\/blog\/#organization","name":"Kanhasoft","url":"https:\/\/kanhasoft.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kanhasoft.com\/blog\/#\/schema\/logo\/image\/","url":"http:\/\/192.168.1.31:890\/blog\/wp-content\/uploads\/2022\/04\/cropped-cropped-Kahnasoft-Web-and-mobile-app-development-1.png","contentUrl":"http:\/\/192.168.1.31:890\/blog\/wp-content\/uploads\/2022\/04\/cropped-cropped-Kahnasoft-Web-and-mobile-app-development-1.png","width":239,"height":56,"caption":"Kanhasoft"},"image":{"@id":"https:\/\/kanhasoft.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/kanhasoft","https:\/\/x.com\/kanhasoft","https:\/\/www.instagram.com\/kanhasoft\/","https:\/\/www.linkedin.com\/company\/kanhasoft\/","https:\/\/in.pinterest.com\/kanhasoft\/_created\/"]},{"@type":"Person","@id":"https:\/\/kanhasoft.com\/blog\/#\/schema\/person\/037907a7ce62ee1ceed7a91652b16122","name":"Manoj Bhuva","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/675e142db3f0e3e42ef6c7f7a13c6f72ac33412f2d0096e342e8033f8388238a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/675e142db3f0e3e42ef6c7f7a13c6f72ac33412f2d0096e342e8033f8388238a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/675e142db3f0e3e42ef6c7f7a13c6f72ac33412f2d0096e342e8033f8388238a?s=96&d=mm&r=g","caption":"Manoj Bhuva"},"sameAs":["https:\/\/kanhasoft.com\/"],"url":"https:\/\/kanhasoft.com\/blog\/author\/ceo\/"}]}},"_links":{"self":[{"href":"https:\/\/kanhasoft.com\/blog\/wp-json\/wp\/v2\/posts\/2395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kanhasoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kanhasoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kanhasoft.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/kanhasoft.com\/blog\/wp-json\/wp\/v2\/comments?post=2395"}],"version-history":[{"count":26,"href":"https:\/\/kanhasoft.com\/blog\/wp-json\/wp\/v2\/posts\/2395\/revisions"}],"predecessor-version":[{"id":6239,"href":"https:\/\/kanhasoft.com\/blog\/wp-json\/wp\/v2\/posts\/2395\/revisions\/6239"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kanhasoft.com\/blog\/wp-json\/wp\/v2\/media\/2410"}],"wp:attachment":[{"href":"https:\/\/kanhasoft.com\/blog\/wp-json\/wp\/v2\/media?parent=2395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kanhasoft.com\/blog\/wp-json\/wp\/v2\/categories?post=2395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kanhasoft.com\/blog\/wp-json\/wp\/v2\/tags?post=2395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}