Download the PHP package musonza/chat without Composer
On this page you can find all versions of the php package musonza/chat. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package chat
Chat
Create a Chat application for your multiple Models
What to learn how to make a package like this? https://leanpub.com/laravel-package-development
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
Introduction
This package allows you to add a chat system to your Laravel ^5.4 application
Installation
From the command line, run:
Publish the assets:
This will publish database migrations and a configuration file musonza_chat.php
in the Laravel config folder.
Configuration
See musonza_chat.php
for configuration
Run the migrations:
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
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:
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:
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:
Creating a conversation
You can start a conversation by passing an array of Models as participants
Creating a conversation of type private / public
You may want to classify conversations as private or public
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
Update conversation details
Send a text message
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:
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.
Get a message by id
Get message sender
Mark a message as read
Flag / mark a message
Mark whole conversation as read
Unread messages count
Unread messages count per Conversation
Delete a message
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
Get participant conversations
Get a conversation between two participants
Get common conversations among participants
$participants
is an array of participant Models
Remove participants from a conversation
Add participants to a conversation
Get messages in a conversation
Get user conversations by type
Get recent messages
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:
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 participation entry for a Model in a conversation
Update participation settings
Set Conversation settings for participant (example: mute_mentions, mute_conversation)
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.
All you need to do is specify the location of your transformers in the configuration
file musonza_chat.php
as follows:
Note: This only applies to responses from package routes.
License
Chat is open-sourced software licensed under the MIT license
All versions of chat with dependencies
illuminate/contracts Version ^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
spatie/laravel-fractal Version ^6.0|dev-main
laravel/legacy-factories Version ^1.0