{"id":14974864,"url":"https://github.com/musonza/chat","last_synced_at":"2026-01-02T04:44:56.777Z","repository":{"id":37612134,"uuid":"54214978","full_name":"musonza/chat","owner":"musonza","description":"A Laravel chat package. You can use this package to create a chat/messaging Laravel application.","archived":false,"fork":false,"pushed_at":"2024-12-30T00:27:02.000Z","size":422,"stargazers_count":1160,"open_issues_count":59,"forks_count":311,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-04-27T04:38:23.375Z","etag":null,"topics":["chat","chatapp","conversation","laravel","laravel-chat","laravel-messaging","laravel-messaging-package","laravel-package","laravel10","laravel7","laravel8","participant-conversations","php","php-chat"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/musonza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://www.paypal.me/tinashemusonza"]}},"created_at":"2016-03-18T16:14:24.000Z","updated_at":"2025-04-25T05:22:45.000Z","dependencies_parsed_at":"2025-02-12T00:15:25.713Z","dependency_job_id":null,"html_url":"https://github.com/musonza/chat","commit_stats":{"total_commits":172,"total_committers":28,"mean_commits":6.142857142857143,"dds":"0.33720930232558144","last_synced_commit":"8f03df6143f88e5df0589d785521d0d9fd9b79c2"},"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/musonza%2Fchat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/musonza%2Fchat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/musonza%2Fchat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/musonza%2Fchat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/musonza","download_url":"https://codeload.github.com/musonza/chat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251089405,"owners_count":21534511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chat","chatapp","conversation","laravel","laravel-chat","laravel-messaging","laravel-messaging-package","laravel-package","laravel10","laravel7","laravel8","participant-conversations","php","php-chat"],"created_at":"2024-09-24T13:51:11.483Z","updated_at":"2026-01-02T04:44:56.772Z","avatar_url":"https://github.com/musonza.png","language":"PHP","funding_links":["https://www.paypal.me/tinashemusonza"],"categories":["PHP"],"sub_categories":[],"readme":"\u003cp align=\"left\"\u003e\u003cimg src=\"menu.png\" alt=\"chat\" width=\"130px\"\u003e\u003c/p\u003e\n\n[![Build Status](https://travis-ci.org/musonza/chat.svg?branch=master)](https://app.travis-ci.com/github/musonza/chat)\n[![Downloads](https://poser.pugx.org/musonza/chat/d/total.svg)](https://packagist.org/packages/musonza/chat)\n[![Packagist](https://img.shields.io/packagist/v/musonza/chat.svg)](https://packagist.org/packages/musonza/chat)\n\n## Chat\n\nCreate a Chat application for your multiple Models\n\n**********************************************************\n**What to learn how to make a package like this? https://leanpub.com/laravel-package-development**\n***************************************************************************************************\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Adding the ability to participate to a Model](#Adding-the-ability-to-participate-to-a-Model)\n  - [Enable the routes](#enable-the-routes)\n  - [Get participant details](#get-participant-details)\n  - [Creating a conversation](#creating-a-conversation)\n  - [Get a conversation by Id](#get-a-conversation-by-id)\n  - [Update conversation details](#update-conversation-details)\n  - [Send a text message](#send-a-text-message)\n  - [Send a message of custom type](#send-a-message-of-custom-type)\n  - [Get a message by id](#get-a-message-by-id)\n  - [Get message sender](#Get-message-sender)\n  - [Mark a message as read](#mark-a-message-as-read)\n  - [Mark whole conversation as read](#mark-whole-conversation-as-read)\n  - [Unread messages count](#unread-messages-count)\n  - [Delete a message](#delete-a-message)\n  - [Cleanup Deleted Messages](#cleanup-deleted-messages)\n  - [Clear a conversation](#clear-a-conversation)\n  - [Get participant conversations](#Get-participant-conversations)\n  - [Get a conversation between two participants](#get-a-conversation-between-two-participants)\n  - [Get common conversations among participants](#get-common-conversations-among-participants)\n  - [Remove participants from a conversation](#remove-participants-from-a-conversation)\n  - [Add participants to a conversation](#add-participants-to-a-conversation)\n  - [Get messages in a conversation](#get-messages-in-a-conversation)\n  - [Get public conversations for discovery](#get-public-conversations-for-discovery)\n  - [Get recent messages](#get-recent-messages)\n  - [Get participants in a conversation](#get-participants-in-a-conversation)\n  - [Get participation entry for a Model in a conversation](#Get-participation-entry-for-a-Model-in-a-conversation)\n  - [Update participation settings](#Update-participation-settings)\n  - [Data Transformers](#Data-Transformers)\n  - [Message Encryption](#message-encryption)\n- [License](#license)\n\nCheckout a simple [Demo Application](https://github.com/musonza/chat-demo)\n\n## Introduction\n\nThis package allows you to add a chat system to your Laravel ^5.4 application\n\n## Installation\n\nFrom the command line, run:\n\n```\ncomposer require musonza/chat\n```\n\nPublish the assets:\n\n```\nphp artisan vendor:publish --provider=\"Musonza\\Chat\\ChatServiceProvider\"\n```\n\nThis will publish database migrations and a configuration file `musonza_chat.php` in the Laravel config folder.\n\n## Configuration\n\nSee `musonza_chat.php` for configuration\n\nRun the migrations:\n\n```\nphp artisan migrate\n```\n\n## Usage\n\nYou can mix Models as participants. For instance you can have `Parents`, `Students` and `Professors` models communicating\n\n#### Adding the ability to participate to a Model \n\nAdd the `Musonza\\Chat\\Traits\\Messageable` trait to any Model you want to participate in Conversations\nFor example, let's say we want out `Bot` model to chat with other Models:\n\n```php\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Musonza\\Chat\\Traits\\Messageable;\n\nclass Bot extends Model\n{\n    use Messageable;\n}\n```\n\n#### Enable the routes\n\nThe package includes routes for conversations, conversation participants, and messaging. These routes are hidden by default. To enable them, change `should_load_routes` to `true`, but make sure to configure the middleware correctly. \n\n#### Get participant details\n\nSince we allow Models with data that differ in structure to chat, we may want a uniform way to\nrepresent the participant details in a uniform way.\n\nYou can get the details as follows:\n\n```php\n$participantModel-\u003egetParticipantDetails();\n```\nAssuming you have a column `name` for your model, this returns a default array `['name' =\u003e 'column_value']`\nYou can however, customize this for your needs by adding an Eloquent Accessor that returns an array\n with as much as you need to your model as follows:\n\n```php\n    public function getParticipantDetailsAttribute()\n    {\n        return [\n            'name' =\u003e $this-\u003esomeValue,\n            'foo' =\u003e 'bar',\n        ];\n    }\n```\n\n#### Creating a conversation\nYou can start a conversation by passing an array of Models as participants\n\n```php\n$participants = [$model1, $model2,..., $modelN];\n\n$conversation = Chat::createConversation($participants);\n```\n\n#### Creating a conversation of type private / public\nYou may want to classify conversations as private or public\n\n```php\n$participants = [$model1, $model2,..., $modelN];\n\n// Create a private conversation\n$conversation = Chat::createConversation($participants)-\u003emakePrivate();\n\n// Create a public conversation\n$conversation = Chat::createConversation($participants)-\u003emakePrivate(false);\n\n// Create a direct message\n\n// Make direct conversation after creation\n$conversation = Chat::createConversation($participants)-\u003emakeDirect();\n\n// Specify intent for direct conversation before creation\n$conversation = Chat::makeDirect()-\u003ecreateConversation($participants);\n```\n\n\u003e **Note:** You will not be able to add additional participants to a direct conversation. \nAdditionally you can't remove a participant from a direct conversation.\n\n#### Get a conversation by id\n```php\n$conversation = Chat::conversations()-\u003egetById($id);\n```\n\n#### Update conversation details\n\n```php\n$data = ['title' =\u003e 'PHP Channel', 'description' =\u003e 'PHP Channel Description'];\n$conversation-\u003eupdate(['data' =\u003e $data]);\n```\n\n#### Send a text message\n\n```php\n$message = Chat::message('Hello')\n            -\u003efrom($model)\n            -\u003eto($conversation)\n            -\u003esend();\n```\n#### Send a message of custom type\n\nThe default message type is `text`. If you want to specify custom type you can call the `type()` function as below:\n\n```php\n$message = Chat::message('http://example.com/img')\n\t\t-\u003etype('image')\n\t\t-\u003efrom($model)\n\t\t-\u003eto($conversation)\n\t\t-\u003esend();\n```\n#### To add more details about a message\n\nSometimes 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.\n\n```php\n$message = Chat::message('Attachment 1')\n\t\t-\u003etype('attachment')\n\t\t-\u003edata(['file_name' =\u003e 'post_image.jpg', 'file_url' =\u003e 'http://example.com/post_img.jpg'])\n\t\t-\u003efrom($model)\n\t\t-\u003eto($conversation)\n\t\t-\u003esend();\n```\n\n### Get a message by id\n\n```php\n$message = Chat::messages()-\u003egetById($id);\n```\n\n### Get message sender\n\n```php\n$sendModel = $message-\u003esender;\n```\n\n#### Mark a message as read\n\n```php\nChat::message($message)-\u003esetParticipant($participantModel)-\u003emarkRead();\n```\n\n#### Flag / mark a message\n\n```php\nChat::message($message)-\u003esetParticipant($participantModel)-\u003etoggleFlag();\n\nChat::message($message)-\u003esetParticipant($participantModel)-\u003eflagged(); // true\n```\n\n#### Mark whole conversation as read\n\n```php\nChat::conversation($conversation)-\u003esetParticipant($participantModel)-\u003ereadAll();\n```\n\n#### Unread messages count\n\n```php\n$unreadCount = Chat::messages()-\u003esetParticipant($participantModel)-\u003eunreadCount();\n```\n\n#### Unread messages count per Conversation\n\n```php\nChat::conversation($conversation)-\u003esetParticipant($participantModel)-\u003eunreadCount();\n```\n\n#### Delete a message\n\n```php\nChat::message($message)-\u003esetParticipant($participantModel)-\u003edelete();\n```\n\n#### Cleanup Deleted Messages\n\nWhat to cleanup when all participants have deleted a `$message` or `$conversation`?\n\nListen for `\\Musonza\\Chat\\Eventing\\AllParticipantsDeletedMessage` and \n\n`\\Musonza\\Chat\\Eventing\\AllParticipantsClearedConversation`\n\n#### Clear a conversation\n\n```php\nChat::conversation($conversation)-\u003esetParticipant($participantModel)-\u003eclear();\n```\n\n#### Get participant conversations\n\n```php\nChat::conversations()-\u003esetPaginationParams(['sorting' =\u003e 'desc'])\n\t-\u003esetParticipant($participantModel)\n\t-\u003elimit(1)\n\t-\u003epage(1)\n\t-\u003eget();\n```\n\n#### Get a conversation between two participants\n\n```php\n$conversation = Chat::conversations()-\u003ebetween($participantModel1, $participantModel2);\n```\n\n#### Get common conversations among participants\n\n```php\n$conversations = Chat::conversations()-\u003ecommon($participants);\n```\n`$participants` is an array of participant Models\n\n#### Remove participants from a conversation\n\n```php\n/* removing one user */\nChat::conversation($conversation)-\u003eremoveParticipants([$participantModel]);\n```\n\n```php\n/* removing multiple participants */\nChat::conversation($conversation)-\u003eremoveParticipants([$participantModel, $participantModel2,...,$participantModelN]);\n```\n\n#### Add participants to a conversation\n\n```php\n/* add one user */\nChat::conversation($conversation)-\u003eaddParticipants([$participantModel]);\n```\n\n```php\n/* add multiple participants */\nChat::conversation($conversation)-\u003eaddParticipants([$participantModel, $participantModel2]);\n```\n\n#### Get messages in a conversation\n\n```php\nChat::conversation($conversation)-\u003esetParticipant($participantModel)-\u003egetMessages()\n```\n\n#### Get user conversations by type\n\n```php\n// private conversations\n$conversations = Chat::conversations()-\u003esetParticipant($participantModel)-\u003eisPrivate()-\u003eget();\n\n// public conversations\n$conversations = Chat::conversations()-\u003esetParticipant($participantModel)-\u003eisPrivate(false)-\u003eget();\n\n// direct conversations / messages\n$conversations = Chat::conversations()-\u003esetParticipant($participantModel)-\u003eisDirect()-\u003eget();\n\n// all conversations\n$conversations = Chat::conversations()-\u003esetParticipant($participantModel)-\u003eget();\n```\n\n#### Get public conversations for discovery\n\nYou can list public conversations without being a participant. This is useful for building discovery pages where users can browse and join public chat rooms (similar to Telegram public groups).\n\n```php\n// Get all public conversations (no participant required)\n$conversations = Chat::conversations()\n    -\u003eisPrivate(false)\n    -\u003elimit(10)\n    -\u003epage(1)\n    -\u003eget();\n```\n\n\u003e **Note:** This only works for public conversations. Attempting to list private conversations without setting a participant will throw an `InvalidConversationListException`.\n\n#### Get recent messages\n\n```php\n$messages = Chat::conversations()-\u003esetParticipant($participantModel)-\u003elimit(25)-\u003epage(1)-\u003eget();\n```\n\n#### Pagination\n\nThere are a few ways you can achieve pagination\nYou can specify the `limit` and `page` as above using the respective functions or as below:\n```\n   $paginated = Chat::conversations()-\u003esetParticipant($participant)\n            -\u003esetPaginationParams([\n                'page' =\u003e 3,\n                'perPage' =\u003e 10,\n                'sorting' =\u003e \"desc\",\n                'columns' =\u003e [\n                    '*'\n                ],\n                'pageName' =\u003e 'test'\n            ])\n            -\u003eget();\n```\nYou don't have to specify all the parameters. If you leave the parameters out, default values will be used.\n`$paginated` above will return `Illuminate\\Pagination\\LengthAwarePaginator`\nTo get the `conversations` simply call `$paginated-\u003eitems()`\n\n\n#### Get participants in a conversation\n\n```php\n$participants = $conversation-\u003egetParticipants();\n```\n\n#### Get participation entry for a Model in a conversation\n\n```php\nChat::conversation($conversation)-\u003egetParticipation($model);\n```\n\n#### Update participation settings\n\nSet Conversation settings for participant (example: mute_mentions, mute_conversation)\n\n```php\n$settings = ['mute_mentions' =\u003e true];\n\nChat::conversation($conversation)\n    -\u003egetParticipation($this-\u003ealpha)\n    -\u003eupdate(['settings' =\u003e $settings]);\n```\n\n#### Data Transformers\n\nNeed to have more control on the data returned from the package routes? You can \nspecify your own Model transformers and take advantage of [Fractal](http://fractal.thephpleague.com/).\n\nAll you need to do is specify the location of your transformers in the configuration\nfile `musonza_chat.php` as follows:\n\n```php\n/**\n * Model Transformers\n */\n'transformers' =\u003e [\n    'conversation' =\u003e \\MyApp\\Transformers\\ConversationTransformer::class,\n    'message' =\u003e \\MyApp\\Transformers\\MessageTransformer::class,\n    'participant' =\u003e \\MyApp\\Transformers\\ParticipantTransformer::class,\n]\n```\n\u003e **Note:** This only applies to responses from package routes.\n\n#### Message Encryption\n\nYou can optionally encrypt message bodies at rest using Laravel's built-in encryption. When enabled, messages are encrypted using AES-256-CBC via Laravel's `Crypt` facade.\n\nTo enable encryption, set the `encrypt_messages` option in your `musonza_chat.php` config file:\n\n```php\n'encrypt_messages' =\u003e true,\n```\n\n**How it works:**\n\n- New messages are automatically encrypted before being stored in the database\n- Messages are automatically decrypted when retrieved via the model\n- Existing unencrypted messages remain readable (hybrid mode)\n- An `is_encrypted` column tracks whether each message is encrypted\n\n```php\n// Sending works the same - encryption is transparent\n$message = Chat::message('Secret message')\n    -\u003efrom($user)\n    -\u003eto($conversation)\n    -\u003esend();\n\n// Reading works the same - decryption is automatic\necho $message-\u003ebody; // \"Secret message\"\n```\n\n\u003e **Note:** Encryption uses your application's `APP_KEY`. If you change your `APP_KEY`, previously encrypted messages will become unreadable.\n\n## License\n\nChat is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmusonza%2Fchat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmusonza%2Fchat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmusonza%2Fchat/lists"}