PHPackages                             muba00/laravel-live-chat - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. muba00/laravel-live-chat

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

muba00/laravel-live-chat
========================

A Laravel package that adds real time live chat functionality to your application.

v0.0.2(6mo ago)02MITPHPPHP ^8.3CI passing

Since Oct 17Pushed 6mo agoCompare

[ Source](https://github.com/muba00/laravel-live-chat)[ Packagist](https://packagist.org/packages/muba00/laravel-live-chat)[ Docs](https://github.com/muba00/laravel-live-chat)[ GitHub Sponsors](https://github.com/muba00)[ RSS](/packages/muba00-laravel-live-chat/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (13)Versions (4)Used By (0)

Laravel Live Chat
=================

[](#laravel-live-chat)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1033e25b55e5d1eb2b1253b8adaf429e185679868b69d82ed6270efb1570baae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d75626130302f6c61726176656c2d6c6976652d636861742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/muba00/laravel-live-chat)[![GitHub Tests Action Status](https://camo.githubusercontent.com/52b3967501122ea2ac0ae256ba327b27dc9054184cbdb54644df59496dcd735c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d75626130302f6c61726176656c2d6c6976652d636861742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/muba00/laravel-live-chat/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/b49350d67e4236f0479a2f1043d18a7e8de98f5fef9cb82c8476d01183031202/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d75626130302f6c61726176656c2d6c6976652d636861742f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/muba00/laravel-live-chat/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/367e0913c308b3bf94234512d7d11640ae85c8ddaae201998408ce7ef45fd11d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d75626130302f6c61726176656c2d6c6976652d636861742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/muba00/laravel-live-chat)

A simple, elegant Laravel package that adds **real-time 1-to-1 chat** functionality to your application using **Laravel Reverb**. Easy to install, easy to use, and follows Laravel best practices.

✨ Features
----------

[](#-features)

- 🚀 **Real-time messaging** using Laravel Reverb WebSockets
- 💬 **1-to-1 conversations** between users
- ✅ **Read receipts** to track message status
- ✍️ **Typing indicators** for better UX
- 🔒 **Built-in authorization** policies
- ️ **Highly configurable** with sensible defaults
- 🧪 **Thoroughly tested** with 100+ tests
- 📦 **Easy to remove** - clean uninstall with no residual code

> **🎨 Frontend Components Coming Soon!** Complete React, Vue 3, and Livewire UI components are currently in development. For now, you can use the backend API to build your own custom frontend.

📋 Requirements
--------------

[](#-requirements)

- PHP 8.3+
- Laravel 11.0+
- Laravel Reverb (for real-time features)
- Laravel Sanctum (for API authentication)

🚀 Quick Start
-------------

[](#-quick-start)

### 1. Install the Package

[](#1-install-the-package)

```
composer require muba00/laravel-live-chat
```

### 2. Run the Installer

[](#2-run-the-installer)

```
php artisan live-chat:install
```

This interactive command will:

- Check prerequisites
- Publish configuration files
- Publish and run migrations
- Guide you through additional setup steps

### 3. Configure Broadcasting

[](#3-configure-broadcasting)

Install Laravel Reverb:

```
composer require laravel/reverb
php artisan reverb:install
```

### 4. Configure Authentication

[](#4-configure-authentication)

If not already done, install Laravel Sanctum:

```
composer require laravel/sanctum
php artisan install:api
```

### 5. Install Frontend Dependencies

[](#5-install-frontend-dependencies)

```
npm install --save-dev laravel-echo pusher-js
npm run build
```

### 6. Start Using the Chat!

[](#6-start-using-the-chat)

**Backend - Create a conversation and send a message:**

```
use muba00\LaravelLiveChat\Models\Conversation;
use muba00\LaravelLiveChat\Models\Message;

// Get or create a conversation between two users
$conversation = Conversation::between(auth()->user(), $otherUser);

// Send a message
$message = Message::create([
    'conversation_id' => $conversation->id,
    'sender_id' => auth()->id(),
    'message' => 'Hello! How are you?',
]);
```

**Frontend - Build your own custom UI:**

Use the provided API endpoints to build your custom chat interface. Complete frontend components for React, Vue 3, and Livewire are coming soon!

📖 Documentation
---------------

[](#-documentation)

### Installation

[](#installation)

#### Manual Installation (Alternative)

[](#manual-installation-alternative)

If you prefer to install manually instead of using the installer command:

```
# Install package
composer require muba00/laravel-live-chat

# Publish config
php artisan vendor:publish --tag="laravel-live-chat-config"

# Publish migrations
php artisan vendor:publish --tag="laravel-live-chat-migrations"

# Run migrations
php artisan migrate
```

### Configuration

[](#configuration)

The package configuration file is published to `config/live-chat.php`. Here are the key configuration options:

```
return [
    // User model configuration
    'user_model' => 'App\\Models\\User',

    // Customize table names
    'tables' => [
        'conversations' => 'live_chat_conversations',
        'messages' => 'live_chat_messages',
    ],

    // API routes configuration
    'routes' => [
        'enabled' => true,
        'prefix' => 'chat/api',
        'middleware' => ['api', 'auth:sanctum'],
    ],

    // Broadcasting settings
    'broadcasting' => [
        'enabled' => true,
        'channel_prefix' => 'chat',
    ],

    // Pagination
    'pagination' => [
        'messages_per_page' => 50,
        'conversations_per_page' => 20,
    ],

    // Message retention and storage
    'storage' => [
        'retention_days' => null, // null = keep forever
        'archive_enabled' => false,
        'max_message_length' => 5000,
    ],

    // Feature toggles
    'features' => [
        'read_receipts' => true,
        'typing_indicators' => true,
    ],

    // Security settings
    'security' => [
        'sanitize_messages' => true,
        'max_conversations_per_user' => 100,
    ],
];
```

#### Environment Variables

[](#environment-variables)

You can override configuration using environment variables:

```
CHAT_USER_MODEL="App\Models\User"
CHAT_MESSAGES_PER_PAGE=50
CHAT_CONVERSATIONS_PER_PAGE=20
CHAT_RETENTION_DAYS=90
CHAT_CACHE_ENABLED=true
CHAT_CACHE_TTL=3600
```

### Usage

[](#usage)

#### Backend API

[](#backend-api)

The package automatically registers RESTful API routes:

```
POST   /chat/api/conversations                           # Create/get conversation
GET    /chat/api/conversations                           # List user's conversations
GET    /chat/api/conversations/{id}                      # Get conversation details
DELETE /chat/api/conversations/{id}                      # Delete conversation

GET    /chat/api/conversations/{id}/messages             # Get messages
POST   /chat/api/conversations/{id}/messages             # Send message
POST   /chat/api/conversations/{id}/messages/mark-read   # Mark messages as read
GET    /chat/api/conversations/{id}/messages/unread-count # Get unread count

POST   /chat/api/conversations/{id}/typing               # Broadcast typing indicator

```

#### Using Models

[](#using-models)

```
use muba00\LaravelLiveChat\Models\Conversation;
use muba00\LaravelLiveChat\Models\Message;

// Get or create a conversation
$conversation = Conversation::between($user1, $user2);

// Check if a user is part of a conversation
$conversation->includesUser($user);

// Get the other user in a conversation
$otherUser = $conversation->getOtherUser(auth()->user());

// Send a message
$message = Message::create([
    'conversation_id' => $conversation->id,
    'sender_id' => auth()->id(),
    'message' => 'Hello!',
]);

// Mark messages as read
$conversation->markAsReadBy(auth()->user());

// Get unread message count
$unreadCount = $conversation->unreadMessagesFor(auth()->user())->count();
```

#### Frontend Integration

[](#frontend-integration)

The package provides a RESTful API for building custom chat interfaces. Complete frontend components for React, Vue 3, and Livewire are currently in development.

##### Example API Usage

[](#example-api-usage)

```
// Fetch conversations
const response = await fetch("/chat/api/conversations", {
    headers: {
        Authorization: `Bearer ${token}`,
        Accept: "application/json",
    },
});
const conversations = await response.json();

// Send a message
await fetch(`/chat/api/conversations/${conversationId}/messages`, {
    method: "POST",
    headers: {
        Authorization: `Bearer ${token}`,
        "Content-Type": "application/json",
        Accept: "application/json",
    },
    body: JSON.stringify({ message: "Hello!" }),
});

// Listen for real-time messages
Echo.private(`chat.${conversationId}`).listen("MessageSent", (event) => {
    console.log("New message:", event.message);
});
```

### Broadcasting Setup

[](#broadcasting-setup)

#### Configure Laravel Reverb

[](#configure-laravel-reverb)

Add to your `.env`:

```
BROADCAST_CONNECTION=reverb

REVERB_APP_ID=your-app-id
REVERB_APP_KEY=your-app-key
REVERB_APP_SECRET=your-app-secret
REVERB_HOST="localhost"
REVERB_PORT=8080
REVERB_SCHEME=http
```

#### Setup Laravel Echo

[](#setup-laravel-echo)

In your `resources/js/bootstrap.js`:

```
import Echo from "laravel-echo";
import Pusher from "pusher-js";

window.Pusher = Pusher;

window.Echo = new Echo({
    broadcaster: "reverb",
    key: import.meta.env.VITE_REVERB_APP_KEY,
    wsHost: import.meta.env.VITE_REVERB_HOST,
    wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
    wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
    forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? "https") === "https",
    enabledTransports: ["ws", "wss"],
});
```

#### Start Reverb Server

[](#start-reverb-server)

```
php artisan reverb:start
```

For production, use a process manager like Supervisor.

### Artisan Commands

[](#artisan-commands)

#### Install Command

[](#install-command)

```
php artisan live-chat:install [options]

Options:
  --force            Overwrite existing files
  --skip-migrations  Skip publishing migrations
  --skip-config      Skip publishing config
```

#### Cleanup Command

[](#cleanup-command)

```
php artisan live-chat:cleanup [options]

Options:
  --days=X          Number of days to retain (overrides config)
  --archive         Archive messages instead of deleting
  --dry-run         Show what would be deleted without deleting
  --force           Skip confirmation prompt
```

**Schedule cleanup automatically:**

```
// In app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
    // Clean up messages older than 90 days, daily at 2 AM
    $schedule->command('live-chat:cleanup --days=90 --force')
        ->dailyAt('02:00');
}
```

### Security

[](#security)

The package includes built-in authorization:

- Users can only access conversations they're part of
- Messages are validated before storage
- XSS protection via message sanitization
- Rate limiting support
- Private broadcast channels with authorization

### Customization

[](#customization)

#### Customize Models

[](#customize-models)

You can extend the package models in your application:

```
namespace App\Models;

use muba00\LaravelLiveChat\Models\Conversation as BaseConversation;

class Conversation extends BaseConversation
{
    // Add your custom methods and properties
}
```

Then update your config to use your custom model.

#### Disable Auto-registered Routes

[](#disable-auto-registered-routes)

```
// In config/live-chat.php
'routes' => [
    'enabled' => false,
],
```

Then register routes manually in your `routes/api.php`.

🧪 Testing
---------

[](#-testing)

```
composer test
composer test-coverage
composer analyse
composer format
```

🗑️ Uninstalling
---------------

[](#️-uninstalling)

```
# Rollback migrations
php artisan migrate:rollback

# Remove published assets (optional)
rm config/live-chat.php

# Remove package
composer remove muba00/laravel-live-chat
```

📚 Additional Resources
----------------------

[](#-additional-resources)

- [API Reference](docs/api-reference.md)

🐛 Troubleshooting
-----------------

[](#-troubleshooting)

### Messages not appearing in real-time

[](#messages-not-appearing-in-real-time)

1. Check Reverb is running: `php artisan reverb:start`
2. Verify `.env` configuration for Reverb
3. Check browser console for WebSocket errors
4. Ensure Laravel Echo is properly initialized

### Authorization errors

[](#authorization-errors)

1. Verify Sanctum is installed and configured
2. Check API token is being sent in requests
3. Ensure user is part of the conversation

### Database errors

[](#database-errors)

1. Run migrations: `php artisan migrate`
2. Check table names in config match your setup
3. Verify user model configuration

🤝 Contributing
--------------

[](#-contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

🔒 Security Vulnerabilities
--------------------------

[](#-security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

📝 Changelog
-----------

[](#-changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

👏 Credits
---------

[](#-credits)

- [Mubariz Hajimuradov](https://github.com/muba00)
- [All Contributors](../../contributors)

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance66

Regular maintenance activity

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

207d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/182f07da8bb65ea20e8c2dd9d69d8b6fd7722b9741ae623ca0ab593e4c244c76?d=identicon)[muba00](/maintainers/muba00)

---

Top Contributors

[![muba00](https://avatars.githubusercontent.com/u/11701997?v=4)](https://github.com/muba00 "muba00 (54 commits)")[![openhands-agent](https://avatars.githubusercontent.com/u/175740463?v=4)](https://github.com/openhands-agent "openhands-agent (4 commits)")

---

Tags

laravelMubariz Hajimuradovlaravel-live-chat

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/muba00-laravel-live-chat/health.svg)

```
[![Health](https://phpackages.com/badges/muba00-laravel-live-chat/health.svg)](https://phpackages.com/packages/muba00-laravel-live-chat)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
