Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Build a Realtime Chat App with Laravel 11, Vue 3 and Pinia
Rating: 4.6 out of 5(16 ratings)
93 students

Build a Realtime Chat App with Laravel 11, Vue 3 and Pinia

Learn how to build a realtime chat app with Laravel 11, Vue 3, Inertia and Reverb, using Pinia for state management
Created byTapan Sharma
Last updated 4/2025
English
English [Auto],

What you'll learn

  • Learn how to Integrate Laravel with Reverb to build Real-Time Applications
  • Learn how to display user typing events using Whisper and implement Client-to-Client communication
  • Learn how to use presence channels to show online users for each room
  • Learn how to use the Intersection Observer API to automatically load previous chat messages
  • Learn State management with Pinia
  • Learn how to use flexbox tricks to keep messages scrolled into view as they roll in
  • Learn how to listen for Broadcasted events from the backend and react to them accordingly
  • Learn how to listen for users leaving or joining events and add/remove them from the online user list

Course content

1 section21 lectures3h 0m total length
  • Installing Laravel2:19

    Install a fresh Laravel project using the Laravel Breeze starter kit with Inertia and Vue.js, configure SQLite, run migrations, and prepare to scaffold chat rooms in the browser.

  • Scaffolding Chat Rooms9:35

    Scaffold chat rooms by defining rooms and messages tables with title and slug, implement room model and controller, and bind routes by slug for inertia rendering.

  • Let's work on the Chat UI3:30

    Refactor the chat UI into modular components—header, messages, nav, and footer—in a chat folder. Display received messages with sender name, content, and time, and sent messages with time only.

  • Building the Chat TextArea10:07

    Replace the default text input with a text area to enable enter submissions and shift-enter for new lines, emitting messages to the parent for backend storage.

  • Seeding Fake Messages in Order10:15

    Seed dummy data for a chat app by creating user, room, and message seeders in Laravel, generating many messages with varied timestamps and random users to power a real-time interface.

  • Creating a Pinia Store6:27

    Install and configure Pinia to manage app state, define a messages store with state and getters, and integrate it into Vue components to fetch and display messages from the backend.

  • Creating the Messages Endpoint6:24

    Create a messages endpoint in Laravel that returns all messages for a specific room, using the room's messages relationship and user data, with eager loading, API resources, and 50-record pagination.

  • Fetching Messages into our Store5:03

    Fetch messages from the backend using the rooms/{roomSlug}/messages API with axios in the Pinia store, supporting pagination, merging data, and enabling infinite scrolling.

  • Displaying the Messages10:56

    Render messages by looping through all messages from the store after fetching them, apply conditional alignment and colors by user, display sender names for received messages, and format timestamps.

  • Ordering Messages with Flexbox4:49

    Use flexbox to reverse message order so the latest appears at the bottom, keep the scroll anchored, and enable infinite scroll to load older messages.

  • Using the Intersection Observer API9:08

    Enable infinite scrolling using the intersection observer from Vue use to load additional data from the backend when the watched element enters the viewport, then merge it with existing messages.

  • Fetching and Pushing Previous Messages9:58

    Use the Intersection Observer API to load previous messages for the room slug when the observed element enters the viewport, incrementing the page and merging data.

  • Storing and Appending Messages11:21

    Implement infinite scrolling to fetch and merge messages, store a new message on enter via the backend, and append it to the timeline with room and user IDs.

  • Setting up Laravel Reverb6:17

    Install and configure Laravel Reverb to enable real-time features in a Laravel 11 app, then emit backend events and listen with Laravel Echo on the client.

  • Broadcasting new Messages18:11

    Broadcast new messages in real time using Laravel 11, Vue 3 and Pinia via Laravel Reverb, WebSockets, and a presence room channel.

  • Handling Broadcasted Messages in our Store7:26

    Listen for the message created event, pass full message data to the front end via a resource, and push it into the message store to update real-time messaging.

  • Fetching Online Users5:50

    Explore presence channels to detect online users for a chat room and display real-time user lists, including authorization and join/leave events in a Laravel 11, Vue 3, and Pinia app.

  • Storing Online User State8:33

    Store online user data in a dedicated Pinia store and expose all users and a count getter. Display online avatars in the navigation by looping the user store data.

  • Keeping Online Users in Sync8:22

    Sync online user lists in real time by listening to join and leave events on the channel, updating the users store with add and remove actions, and preventing duplicates.

  • Detecting Typing Events7:35

    Register a keydown listener on the text area to emit a typing event, and display a typing indicator in the navbar with a three second timeout.

  • Showing when a User is Typing18:45

    Seamlessly implement client-to-client typing indicators by whispering typing events over a presence channel with Laravel Echo, updating the typing state for other connected users without backend requests.

Requirements

  • Beginner level knowledge of PHP/Laravel and VueJS is Required

Description

Using the power of Laravel Reverb, let’s build a real-time multi-room chat application with Laravel 11 and VueJS with InertiaJS,  pulling in Pinia for state management.

We’ll cover:

  • Using the Intersection Observer API to load previous chat messages automatically when the user scrolls to the top of the chat interface

  • Learn how to Use presence channels to show online users for each room

  • Learn how to implement Client-to-client communication using Laravel Echo to show who’s typing and display the typing indicators accordingly

  • Learn how to use Flexbox tricks to keep messages scrolled into view as they roll in

  • Learn database seeding techniques in Laravel

  • Learn how to use API Resources in Laravel

  • Learn how to display better-formatted dates and times

  • Learn how to listen for Broadcasted events from the backend and react to them accordingly

  • We'll also learn how to listen for users leaving or joining events and add/remove them from the online user list

  • All of this state will be managed on the client side, using Pinia


By the end of this course, you will have built a feature-rich, real-time chat application that showcases your understanding of front-end and back-end technologies, perfect for any aspiring developer looking to enhance their skills in dynamic web application development.

Who this course is for:

  • Laravel Developers who want to Build Realtime Applications using InertiaJS, Vue 3 and Reverb