Laravel Reverb: Four "Live" Practical Examples

There are many customer support chat solutions, but sometimes you need something simple. For that, we can use Reverb and create a chat around it:

On the admin side, the administrator user will be able to see the chat requests and reply to them:

With this solution, we don't need to use any third-party free/paid software. We also have complete control over how it works/looks of what happens. Finally, all the data stays on our servers.

Project Overview

Our demo project contains two critical parts in the application:

On the user side - we have a chatbox that will be used to send messages to the support team:

Chatbox has this code inside:

Note: Repository is linked at the end of the tutorial.

<div class="fixed bottom-2 right-2 bg-blue-900 rounded-xl"
style="width: 64px; height: 64px;">
<button id="chatbox-button" class="mx-auto flex justify-center items-center "
style="width: 64px; height: 64px;">
<div id="chatbox-container" class="hidden fixed bottom-24 right-2 bg-gray-200 border-2 border-blue-400"
style="min-width: 400px; max-width: 30%; height: 600px">
<div class="p-6 flex flex-col justify-between h-full">
<div class="pb-4 mb-4 border-b-2 border-b-gray-400">
<h2 class="text-2xl text-center">Chat with Customer Support</h2>
<div class="overflow-y-scroll h-full" id="messagesList">
<div class="">
<div class="font-bold">System</div>
Hello, how can we help you?
<div class="pt-4 mt-4 border-t-2 border-t-gray-400">
<textarea id="message" class="w-full"></textarea>
<button id="sendMessage" class="w-full bg-blue-300 py-2">Send Message</button>
<script type="text/html">
<div class="_POSITION_">
<div class="font-bold">_SENDER_</div>
const MESSAGE_ICON = `
<svg xmlns="" width="32" height="32" viewBox="-3 -2 32 32" fill="none" stroke="#FFFFFF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-mail p-0 m-0">
<path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"></path>
<polyline points="22,6 12,13 2,6"></polyline>
const CLOSE_ICON = `
<svg xmlns="" width="32" height="32" viewBox="-3 -2 32 32" fill="#FFFFFF" stroke="#FFFFFF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x p-0 m-0">
<line x1="18" y1="6" x2="6" y2="18"></line>
<line x1="6" y1="6" x2="18" y2="18"></line>
// Set the session identifier
// This acts as "rooms" for now, and will be cleared on page refresh
let identifier = '{{ auth()->id() }}-{{ uniqid() }}';
// Add default chatbox button icon as soon as page loads
const chatboxButton = document.getElementById('chatbox-button');
chatboxButton.innerHTML = MESSAGE_ICON;
// Add event listener to chatbox button (open/close chatbox)
document.getElementById('chatbox-button').addEventListener('click', function () {
const chatboxContainer = document.getElementById('chatbox-container');
if (chatboxContainer.classList.contains('hidden')) {
chatboxButton.innerHTML = MESSAGE_ICON;
} else {
chatboxButton.innerHTML = CLOSE_ICON;
// Send the message on sendMessage button click
document.getElementById('sendMessage').addEventListener('click', function () {
const message = document.getElementById('message').value;
const messagesList = document.getElementById('messagesList');
const messageTemplate = document.querySelector('script[type="text/html"]').innerHTML;
// Post the message to the server
fetch('{{ route('send-message') }}', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
body: JSON.stringify({message: message, identifier: identifier})
.then(() => {
const newMessage = messageTemplate
.replace('_POSITION_', 'text-right')
.replace('_SENDER_', 'You')
.replace('MESSAGE', message);
messagesList.innerHTML += newMessage;
messagesList.scrollTop = messagesList.scrollHeight;
document.getElementById('message').value = '';

On the support side (admin), we have a list of all user-created chat rooms. From there, we can go inside the chat room and see all the messages that were sent:

We are simply using a controller and a table to display all the chat rooms:


// ...
public function index()
$chatRooms = ChatRoom::query()
->orderBy('updated_at', 'desc')
return view('chatRooms.index', compact('chatRooms'));
// ...


{{-- ... --}}
<table class="w-full">
<th class="border px-4 py-2">ID</th>
<th class="border px-4 py-2">User Name</th>
<th class="border px-4 py-2">Message Count</th>
<th class="border px-4 py-2">Last Update</th>
<th class="border px-4 py-2">Actions</th>
@foreach ($chatRooms as $chatRoom)
<td class="border px-4 py-2">{{ $chatRoom->identifier }}</td>
<td class="border px-4 py-2">{{ $chatRoom->user->name }}</td>
<td class="border px-4 py-2">{{ $chatRoom->chat_messages_count }}</td>
<td class="border px-4 py-2">{{ $chatRoom->updated_at }}</td>
<td class="border px-4 py-2">
<a href="{{ route('', $chatRoom->id) }}"
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">View</a>
{{-- ... --}}

The chat room has this code...

This lesson is only for Premium Members.
Want to access all lessons of this course?

You also get:

  • 59 courses (1057 lessons, 42 h 44 min total)
  • Premium tutorials
  • Access to repositories
  • Private Discord