PHPackages                             zedmagdy/filament-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. zedmagdy/filament-chat

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

zedmagdy/filament-chat
======================

A filament package for creating chat interfaces in your Laravel applications.

v0.8.0(1mo ago)2484[2 PRs](https://github.com/ZED-Magdy/filament-chat/pulls)MITPHPPHP ^8.3CI passing

Since Mar 17Pushed 2d agoCompare

[ Source](https://github.com/ZED-Magdy/filament-chat)[ Packagist](https://packagist.org/packages/zedmagdy/filament-chat)[ Docs](https://github.com/ZED-Magdy/filament-chat)[ GitHub Sponsors](https://github.com/ZED-Magdy)[ RSS](/packages/zedmagdy-filament-chat/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (3)Dependencies (30)Versions (17)Used By (0)

Filament Chat
=============

[](#filament-chat)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4494126f232f9f6641c561b96ba59d0401c29420d09ba070325fd5dc2476bee6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a65646d616764792f66696c616d656e742d636861742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zedmagdy/filament-chat)[![GitHub Tests Action Status](https://camo.githubusercontent.com/e790c4e1bd782e7e39c0e95dffda8fb2447a6e802bfa52862a560500260aedaa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f5a45442d4d616764792f66696c616d656e742d636861742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/ZED-Magdy/filament-chat/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/38bb2522e7fd704d544ef7d4f0b9be383dfa256e5b1efd634ea28837b131271f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a65646d616764792f66696c616d656e742d636861742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zedmagdy/filament-chat)

A chat plugin for Filament v4 that supports configurable chat sources, one-to-one and group conversations, text and file attachments (via Spatie Media Library), read/unread tracking, search, and real-time updates via polling or broadcasting (Reverb/Pusher).

Requirements
------------

[](#requirements)

- PHP ^8.3
- Laravel ^11.0 or ^12.0
- Filament ^4.3.1 or ^5.0
- Spatie Media Library (installed automatically)

Installation
------------

[](#installation)

Install via Composer:

```
composer require zedmagdy/filament-chat
```

Publish and run the migrations:

```
php artisan vendor:publish --tag="filament-chat-migrations"
php artisan migrate
```

If you haven't already, publish the Spatie Media Library migration as well:

```
php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="medialibrary-migrations"
php artisan migrate
```

Optionally publish the config:

```
php artisan vendor:publish --tag="filament-chat-config"
```

Optionally publish the views for customization:

```
php artisan vendor:publish --tag="filament-chat-views"
```

Full Integration Example
------------------------

[](#full-integration-example)

### 1. Add the `HasChats` trait to your User model

[](#1-add-the-haschats-trait-to-your-user-model)

```
namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use ZEDMagdy\FilamentChat\Traits\HasChats;

class User extends Authenticatable
{
    use HasChats;

    // ...
}
```

This gives your User model these relationships:

- `chatParticipations()` - all chat participations
- `conversations()` - all conversations the user is part of
- `sentMessages()` - all messages sent by the user

### 2. Create a Chat Source

[](#2-create-a-chat-source)

The quickest way is with the Artisan command:

```
# Interactive (prompts for name and model)
php artisan make:chat-source

# Non-interactive
php artisan make:chat-source Staff --model=User
```

This generates two files:

- `app/Chat/StaffChatSource.php` — the chat source class
- `app/Filament/Pages/StaffChatPage.php` — the Filament page

Then skip to [step 4](#4-register-the-plugin-in-your-panel) to register it.

#### Manual setup

[](#manual-setup)

A chat source defines a category of chat (e.g. staff-to-staff, patient support). Create one class per source:

```
namespace App\Chat;

use App\Filament\Pages\StaffChatPage;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use ZEDMagdy\FilamentChat\ChatSource;

class StaffChatSource extends ChatSource
{
    public function getKey(): string
    {
        return 'staff';
    }

    public function getLabel(): string
    {
        return 'Staff Chat';
    }

    public function getIcon(): string
    {
        return 'heroicon-o-chat-bubble-left-right';
    }

    public function getParticipantModel(): string
    {
        return User::class;
    }

    public function getPageClass(): string
    {
        return StaffChatPage::class;
    }

    // Optional: filter which users can be added to new conversations
    public function getAvailableParticipantsQuery(): Builder
    {
        return User::query()->where('role', 'staff');
    }

    // Optional: allow users to create new conversations (default: true)
    public function allowsNewConversations(): bool
    {
        return true;
    }

    // Optional: enable group chats for this source (default: false)
    public function allowsGroupChats(): bool
    {
        return true;
    }

    // Optional: customize navigation
    public function getNavigationGroup(): ?string
    {
        return 'Communication';
    }

    public function getNavigationSort(): ?int
    {
        return 1;
    }

    // Optional: customize how participant names are displayed
    public function getParticipantDisplayName(\Illuminate\Database\Eloquent\Model $participant): string
    {
        return $participant->name;
    }

    // Optional: provide avatar URLs
    public function getParticipantAvatarUrl(\Illuminate\Database\Eloquent\Model $participant): ?string
    {
        return $participant->avatar_url;
    }
}
```

### 3. Create a Chat Page

[](#3-create-a-chat-page)

Each chat source needs a thin Filament page class:

```
namespace App\Filament\Pages;

use ZEDMagdy\FilamentChat\Pages\ChatSourcePage;

class StaffChatPage extends ChatSourcePage
{
    protected static string $chatSourceKey = 'staff';
}
```

That's it. The page inherits its navigation label, icon, group, sort, and slug from the chat source.

### 4. Register the Plugin in your Panel

[](#4-register-the-plugin-in-your-panel)

```
namespace App\Providers\Filament;

use App\Chat\StaffChatSource;
use Filament\Panel;
use Filament\PanelProvider;
use ZEDMagdy\FilamentChat\FilamentChatPlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->default()
            ->id('admin')
            ->path('admin')
            // ... other config
            ->plugin(
                FilamentChatPlugin::make()
                    ->sources([
                        StaffChatSource::class,
                    ])
            );
    }
}
```

### 5. Multiple Chat Sources

[](#5-multiple-chat-sources)

You can register multiple sources for different chat contexts:

```
// app/Chat/PatientChatSource.php
namespace App\Chat;

use App\Filament\Pages\PatientChatPage;
use App\Models\Patient;
use ZEDMagdy\FilamentChat\ChatSource;

class PatientChatSource extends ChatSource
{
    public function getKey(): string
    {
        return 'patient';
    }

    public function getLabel(): string
    {
        return 'Patient Messages';
    }

    public function getIcon(): string
    {
        return 'heroicon-o-heart';
    }

    public function getParticipantModel(): string
    {
        return Patient::class; // any model with HasChats trait
    }

    public function getPageClass(): string
    {
        return PatientChatPage::class;
    }
}
```

```
// app/Filament/Pages/PatientChatPage.php
namespace App\Filament\Pages;

use ZEDMagdy\FilamentChat\Pages\ChatSourcePage;

class PatientChatPage extends ChatSourcePage
{
    protected static string $chatSourceKey = 'patient';
}
```

Register both in your panel:

```
->plugin(
    FilamentChatPlugin::make()
        ->sources([
            StaffChatSource::class,
            PatientChatSource::class,
        ])
)
```

### 6. Aggregate Chat Sources ("All Messages")

[](#6-aggregate-chat-sources-all-messages)

An **aggregate page** presents a single read + reply inbox spanning an explicit set of source keys. It does not support starting new conversations (use the per-source pages for that); each row shows a badge indicating which source the conversation belongs to.

Generate one with the `make:chat-aggregate` command:

```
# Interactive (prompts for name and source keys)
php artisan make:chat-aggregate

# Non-interactive
php artisan make:chat-aggregate "All Messages" --sources=staff,support --no-interaction
```

This creates `app/Chat/AllMessagesAggregateChatSource.php`:

```
