PHPackages                             salvation/mongo-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. salvation/mongo-chat

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

salvation/mongo-chat
====================

Chat Package for Laravel in MongoDB

v6.0.0(3y ago)113MITPHPPHP &gt;=8.0

Since Mar 18Pushed 3y agoCompare

[ Source](https://github.com/salvationarinze/mongo-chat)[ Packagist](https://packagist.org/packages/salvation/mongo-chat)[ Fund](https://www.paypal.me/tinashemusonza)[ RSS](/packages/salvation-mongo-chat/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (59)Used By (0)

[![chat](menu.png)](menu.png)

[![Build Status](https://camo.githubusercontent.com/7342bb20f040d8e13e22161b0e2de27b68e6293e0a535c9de569980683dbbe5e/68747470733a2f2f7472617669732d63692e6f72672f6d75736f6e7a612f636861742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/musonza/chat)[![Downloads](https://camo.githubusercontent.com/b3eb9da5bb7ba50fc0e04470be89bc6fa455ea7a02f76c934199b8966be876c2/68747470733a2f2f706f7365722e707567782e6f72672f6d75736f6e7a612f636861742f642f746f74616c2e737667)](https://packagist.org/packages/musonza/chat)[![Packagist](https://camo.githubusercontent.com/b4322a34bf14abd45101cc2050e9faf8ed0691350508e537821e91ad4241bfb6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d75736f6e7a612f636861742e737667)](https://packagist.org/packages/musonza/chat)[![](https://camo.githubusercontent.com/5359a106d1bdcf9fe3dd725e7ece949721c1b53c82a997fe6e8d7ce5375c5346/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f38356631353265616532613034623235373833642f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/musonza/chat/maintainability)

Chat
----

[](#chat)

Create a Chat application for your multiple Models

---

**What to learn how to make a package like this? **

---

Table of Contents
-----------------

[](#table-of-contents)

Click to expand- [Introduction](#introduction)
- [Installation](#installation)
- [Usage](#usage)
    - [Adding the ability to participate to a Model](#Adding-the-ability-to-participate-to-a-Model)
    - [Get participant details](#get-participant-details)
    - [Creating a conversation](#creating-a-conversation)
    - [Get a conversation by Id](#get-a-conversation-by-id)
    - [Update conversation details](#update-conversation-details)
    - [Send a text message](#send-a-text-message)
    - [Send a message of custom type](#send-a-message-of-custom-type)
    - [Get a message by id](#get-a-message-by-id)
    - [Get message sender](#Get-message-sender)
    - [Mark a message as read](#mark-a-message-as-read)
    - [Mark whole conversation as read](#mark-whole-conversation-as-read)
    - [Unread messages count](#unread-messages-count)
    - [Delete a message](#delete-a-message)
    - [Cleanup Deleted Messages](#cleanup-deleted-messages)
    - [Clear a conversation](#clear-a-conversation)
    - [Get participant conversations](#Get-participant-conversations)
    - [Get a conversation between two participants](#get-a-conversation-between-two-participants)
    - [Get common conversations among participants](#get-common-conversations-among-participants)
    - [Remove participants from a conversation](#remove-participants-from-a-conversation)
    - [Add participants to a conversation](#add-participants-to-a-conversation)
    - [Get messages in a conversation](#get-messages-in-a-conversation)
    - [Get recent messages](#get-recent-messages)
    - [Get participants in a conversation](#get-participants-in-a-conversation)
    - [Get participation entry for a Model in a conversation](#Get-participation-entry-for-a-Model-in-a-conversation)
    - [Update participation settings](#Update-participation-settings)
    - [Data Transformers](#Data-Transformers)
- [License](#license)

Checkout a simple [Demo Application](https://github.com/musonza/chat-demo)

Introduction
------------

[](#introduction)

This package allows you to add a chat system to your Laravel ^5.4 application

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

[](#installation)

From the command line, run:

```
composer require musonza/chat

```

Publish the assets:

```
php artisan vendor:publish

```

This will publish database migrations and a configuration file `musonza_chat.php` in the Laravel config folder.

Configuration
-------------

[](#configuration)

See `musonza_chat.php` for configuration

Run the migrations:

```
php artisan migrate

```

Usage
-----

[](#usage)

You can mix Models as participants. For instance you can have `Parents`, `Students` and `Professors` models communicating

#### Adding the ability to participate to a Model

[](#adding-the-ability-to-participate-to-a-model)

Add the `Musonza\Chat\Traits\Messageable` trait to any Model you want to participate in Conversations For example, let's say we want out `Bot` model to chat with other Models:

```
use Jenssegers\Mongodb\Eloquent\Model;
use Musonza\Chat\Traits\Messageable;

class Bot extends Model
{
    use Messageable;
}
```

#### Get participant details

[](#get-participant-details)

Since we allow Models with data that differ in structure to chat, we may want a uniform way to represent the participant details in a uniform way.

You can get the details as follows:

```
$participantModel->getParticipantDetails();
```

Assuming you have a column `name` for your model, this returns a default array `['name' => 'column_value']`You can however, customize this for your needs by adding an Eloquent Accessor that returns an array with as much as you need to your model as follows:

```
    public function getParticipantDetailsAttribute()
    {
        return [
            'name' => $this->someValue,
            'foo' => 'bar',
        ];
    }
```

#### Creating a conversation

[](#creating-a-conversation)

You can start a conversation by passing an array of Models as participants

```
$participants = [$model1, $model2,..., $modelN];

$conversation = Chat::createConversation($participants);
```

#### Creating a conversation of type private / public

[](#creating-a-conversation-of-type-private--public)

You may want to classify conversations as private or public

```
$participants = [$model1, $model2,..., $modelN];

// Create a private conversation
$conversation = Chat::createConversation($participants)->makePrivate();

// Create a public conversation
$conversation = Chat::createConversation($participants)->makePrivate(false);

// Create a direct message

// Make direct conversation after creation
$conversation = Chat::createConversation($participants)->makeDirect();

// Specify intent for direct conversation before creation
$conversation = Chat::makeDirect()->createConversation($participants);
```

> **Note:** You will not be able to add additional participants to a direct conversation. Additionally you can't remove a participant from a direct conversation.

#### Get a conversation by id

[](#get-a-conversation-by-id)

```
$conversation = Chat::conversations()->getById($id);
```

#### Update conversation details

[](#update-conversation-details)

```
$data = ['title' => 'PHP Channel', 'description' => 'PHP Channel Description'];
$conversation->update(['data' => $data]);
```

#### Send a text message

[](#send-a-text-message)

```
$message = Chat::message('Hello')
            ->from($model)
            ->to($conversation)
            ->send();
```

#### Send a message of custom type

[](#send-a-message-of-custom-type)

The default message type is `text`. If you want to specify custom type you can call the `type()` function as below:

```
$message = Chat::message('http://example.com/img')
		->type('image')
		->from($model)
		->to($conversation)
		->send();
```

#### To add more details about a message

[](#to-add-more-details-about-a-message)

Sometimes you might want to add details about a message. For example, when the message type is an attachment, and you want to add details such as attachment's filename, and attachment's file url, you can call the `data()` function and pass your data as an array.

```
$message = Chat::message('Attachment 1')
		->type('attachment')
		->data(['file_name' => 'post_image.jpg', 'file_url' => 'http://example.com/post_img.jpg'])
		->from($model)
		->to($conversation)
		->send();
```

### Get a message by id

[](#get-a-message-by-id)

```
$message = Chat::messages()->getById($id);
```

### Get message sender

[](#get-message-sender)

```
$sendModel = $message->sender;
```

#### Mark a message as read

[](#mark-a-message-as-read)

```
Chat::message($message)->setParticipant($participantModel)->markRead();
```

#### Flag / mark a message

[](#flag--mark-a-message)

```
Chat::message($message)->setParticipant($participantModel)->toggleFlag();

Chat::message($message)->setParticipant($participantModel)->flagged(); // true
```

#### Mark whole conversation as read

[](#mark-whole-conversation-as-read)

```
Chat::conversation($conversation)->setParticipant($participantModel)->readAll();
```

#### Unread messages count

[](#unread-messages-count)

```
$unreadCount = Chat::messages()->setParticipant($participantModel)->unreadCount();
```

#### Unread messages count per Conversation

[](#unread-messages-count-per-conversation)

```
Chat::conversation($conversation)->setParticipant($participantModel)->unreadCount();
```

#### Delete a message

[](#delete-a-message)

```
Chat::message($message)->setParticipant($participantModel)->delete();
```

#### Cleanup Deleted Messages

[](#cleanup-deleted-messages)

What to cleanup when all participants have deleted a `$message` or `$conversation`?

Listen for `\Musonza\Chat\Eventing\AllParticipantsDeletedMessage` and

`\Musonza\Chat\Eventing\AllParticipantsClearedConversation`

#### Clear a conversation

[](#clear-a-conversation)

```
Chat::conversation($conversation)->setParticipant($participantModel)->clear();
```

#### Get participant conversations

[](#get-participant-conversations)

```
Chat::conversations()->setPaginationParams(['sorting' => 'desc'])
	->setParticipant($participantModel)
	->limit(1)
	->page(1)
	->get();
```

#### Get a conversation between two participants

[](#get-a-conversation-between-two-participants)

```
$conversation = Chat::conversations()->between($participantModel1, $participantModel2);
```

#### Get common conversations among participants

[](#get-common-conversations-among-participants)

```
$conversations = Chat::conversations()->common($participants);
```

`$participants` is an array of participant Models

#### Remove participants from a conversation

[](#remove-participants-from-a-conversation)

```
/* removing one user */
Chat::conversation($conversation)->removeParticipants([$participantModel]);
```

```
/* removing multiple participants */
Chat::conversation($conversation)->removeParticipants([$participantModel, $participantModel2,...,$participantModelN]);
```

#### Add participants to a conversation

[](#add-participants-to-a-conversation)

```
/* add one user */
Chat::conversation($conversation)->addParticipants([$participantModel]);
```

```
/* add multiple participants */
Chat::conversation($conversation)->addParticipants([$participantModel, $participantModel2]);
```

#### Get messages in a conversation

[](#get-messages-in-a-conversation)

```
Chat::conversation($conversation)->setParticipant($participantModel)->getMessages()
```

#### Get user conversations by type

[](#get-user-conversations-by-type)

```
// private conversations
$conversations = Chat::conversations()->setParticipant($participantModel)->isPrivate()->get();

// public conversations
$conversations = Chat::conversations()->setParticipant($participantModel)->isPrivate(false)->get();

// direct conversations / messages
$conversations = Chat::conversations()->setParticipant($participantModel)->isDirect()->get();

// all conversations
$conversations = Chat::conversations()->setParticipant($participantModel)->get();
```

#### Get recent messages

[](#get-recent-messages)

```
$messages = Chat::conversations()->setParticipant($participantModel)->limit(25)->page(1)->get();
```

#### Pagination

[](#pagination)

There are a few ways you can achieve pagination You can specify the `limit` and `page` as above using the respective functions or as below:

```
   $paginated = Chat::conversations()->setParticipant($participant)
            ->setPaginationParams([
                'page' => 3,
                'perPage' => 10,
                'sorting' => "desc",
                'columns' => [
                    '*'
                ],
                'pageName' => 'test'
            ])
            ->get();

```

You don't have to specify all the parameters. If you leave the parameters out, default values will be used. `$paginated` above will return `Illuminate\Pagination\LengthAwarePaginator`To get the `conversations` simply call `$paginated->items()`

#### Get participants in a conversation

[](#get-participants-in-a-conversation)

```
$participants = $conversation->getParticipants();
```

#### Get participation entry for a Model in a conversation

[](#get-participation-entry-for-a-model-in-a-conversation)

```
Chat::conversation($conversation)->getParticipation($model);
```

#### Update participation settings

[](#update-participation-settings)

Set Conversation settings for participant (example: mute\_mentions, mute\_conversation)

```
$settings = ['mute_mentions' => true];

Chat::conversation($conversation)
    ->getParticipation($this->alpha)
    ->update(['settings' => $settings]);
```

#### Data Transformers

[](#data-transformers)

Need to have more control on the data returned from the package routes? You can specify your own Model transformers and take advantage of [Fractal](http://fractal.thephpleague.com/).

All you need to do is specify the location of your transformers in the configuration file `musonza_chat.php` as follows:

```
/**
 * Model Transformers
 */
'transformers' => [
    'conversation' => \MyApp\Transformers\ConversationTransformer::class,
    'message' => \MyApp\Transformers\MessageTransformer::class,
    'participant' => \MyApp\Transformers\ParticipantTransformer::class,
]
```

> **Note:** This only applies to responses from package routes.

License
-------

[](#license)

Chat is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor3

3 contributors hold 50%+ of commits

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 ~39 days

Total

58

Last Release

1450d ago

Major Versions

v1.0.0 → v2.0.02017-07-22

v2.1.2 → v3.0.02018-06-02

3.0.x-dev → v4.0.0-rc12019-10-31

v4.6.1 → v5.0.0-beta2021-12-22

1.0.1 → v6.0.02022-05-18

PHP version history (6 changes)v2.0.0PHP &gt;=5.6.0

v3.0.0PHP &gt;=7.0

v3.6.0PHP ^7.2

v3.7.0PHP ^7.1.3|^7.2

v4.5.0PHP &gt;=7.3

v6.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/fcddf32db68c3045ea7c7148d508dc7d14a6fe616c7d88ca0ba3b215d2cf7587?d=identicon)[modernbabbage](/maintainers/modernbabbage)

---

Top Contributors

[![salvationarinze](https://avatars.githubusercontent.com/u/7917974?v=4)](https://github.com/salvationarinze "salvationarinze (17 commits)")[![musonza](https://avatars.githubusercontent.com/u/3452388?v=4)](https://github.com/musonza "musonza (7 commits)")[![ali4zimi](https://avatars.githubusercontent.com/u/13467999?v=4)](https://github.com/ali4zimi "ali4zimi (5 commits)")[![tolgatasci](https://avatars.githubusercontent.com/u/9893685?v=4)](https://github.com/tolgatasci "tolgatasci (4 commits)")[![pajkho](https://avatars.githubusercontent.com/u/8545572?v=4)](https://github.com/pajkho "pajkho (3 commits)")[![moecasts](https://avatars.githubusercontent.com/u/37169906?v=4)](https://github.com/moecasts "moecasts (2 commits)")[![mehranabi](https://avatars.githubusercontent.com/u/30838541?v=4)](https://github.com/mehranabi "mehranabi (2 commits)")[![sonnysantino](https://avatars.githubusercontent.com/u/1275605?v=4)](https://github.com/sonnysantino "sonnysantino (2 commits)")[![abhishekpaul](https://avatars.githubusercontent.com/u/1397474?v=4)](https://github.com/abhishekpaul "abhishekpaul (1 commits)")[![MostafaNobaghi](https://avatars.githubusercontent.com/u/24896868?v=4)](https://github.com/MostafaNobaghi "MostafaNobaghi (1 commits)")[![owenvoke](https://avatars.githubusercontent.com/u/1899334?v=4)](https://github.com/owenvoke "owenvoke (1 commits)")[![rez1dent3](https://avatars.githubusercontent.com/u/5111255?v=4)](https://github.com/rez1dent3 "rez1dent3 (1 commits)")[![shacky](https://avatars.githubusercontent.com/u/6030720?v=4)](https://github.com/shacky "shacky (1 commits)")[![mirzazulfan](https://avatars.githubusercontent.com/u/36124339?v=4)](https://github.com/mirzazulfan "mirzazulfan (1 commits)")[![AleksandarSavic95](https://avatars.githubusercontent.com/u/12213798?v=4)](https://github.com/AleksandarSavic95 "AleksandarSavic95 (1 commits)")[![aren1989](https://avatars.githubusercontent.com/u/10001337?v=4)](https://github.com/aren1989 "aren1989 (1 commits)")[![axe1987](https://avatars.githubusercontent.com/u/25763733?v=4)](https://github.com/axe1987 "axe1987 (1 commits)")[![BenQoder](https://avatars.githubusercontent.com/u/24754078?v=4)](https://github.com/BenQoder "BenQoder (1 commits)")[![danilopinotti](https://avatars.githubusercontent.com/u/11338999?v=4)](https://github.com/danilopinotti "danilopinotti (1 commits)")[![flyingcoder](https://avatars.githubusercontent.com/u/8900451?v=4)](https://github.com/flyingcoder "flyingcoder (1 commits)")

---

Tags

laravelmessagingchatconversation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/salvation-mongo-chat/health.svg)

```
[![Health](https://phpackages.com/badges/salvation-mongo-chat/health.svg)](https://phpackages.com/packages/salvation-mongo-chat)
```

###  Alternatives

[musonza/chat

Chat Package for Laravel

1.2k253.4k1](/packages/musonza-chat)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[bensampo/laravel-embed

Painless responsive embeds for videos, slideshows and more.

142146.8k](/packages/bensampo-laravel-embed)[lexxyungcarter/chatmessenger

Simple one-to-one/group chat messaging tool for Laravel 5, 6, 7, 8, 9 &amp; 10 with Pusher Integration

10724.1k](/packages/lexxyungcarter-chatmessenger)[syntaxlexx/chatmessenger

Simple one-to-one/group chat messaging tool for Laravel 5, 6, 7, 8, 9 &amp; 10 with Pusher Integration

10510.2k](/packages/syntaxlexx-chatmessenger)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

116.6k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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