- Introduction
- Installation
- Usage
- Creating a conversation
- Get a conversation by Id
- Send a text message
- Send a message of custom type
- Mark a message as read
- Mark whole conversation as read
- Delete a message
- Clear a conversation
- Get a conversation between two users
- Remove users from a conversation
- Add users to a conversation
- Get messages in a conversation
- Get recent messages
- Get users in a conversation
- License
This package allows you to add a chat system to your Laravel ^5.3 application
Note: If you are using a Laravel version less than 5.3 install the release on this branch instead.
From the command line, run:
composer require musonza/chat
Add the service provider to your config\app.php the providers array
Musonza\Chat\ChatServiceProvider
Add the Facade to your aliases:
'Chat' => Musonza\Chat\Facades\ChatFacade::class to your `config\app.php`
The class is bound to the ioC as chat
$chat = App::make('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.
Note: This package takes advantage of Laravel Notifications. If you have already setup Laravel notifications you can delete the
2017_07_12_034227_create_notifications_table.phpmigration file.
Run the migrations:
php artisan migrate
By default the package assumes you have a User model in the App namespace.
However, you can update the user model in musonza_chat.php published in the config folder.
$participants = [$userId, $userId2,...];
$conversation = Chat::createConversation($participants);
$conversation = Chat::conversation($conversation_id);
$message = Chat::message('Hello')
->from($user)
->to($conversation)
->send(); 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($user)
->to($conversation)
->send(); Chat::messages($message)->for($user)->markRead();Chat::conversations($conversation)->for($user)->readAll();Chat::messages($message)->for($user)->delete();Chat::conversations($conversation)->for($user)->clear();Chat::getConversationBetween($user1, $user2);/* removing one user */
Chat::removeParticipants($conversation, $user);/* removing multiple users */
Chat::removeParticipants($conversation, [$user1, $user2, $user3,...,$userN]);/* add one user */
Chat::addParticipants($conversation, $user); /* add multiple users */
Chat::addParticipants($conversation, [$user3, $user4]);Note: A third user will classify the conversation as not private if it was.
Chat::conversations($conversation)->for($user)->getMessages($perPage, $page)$messages = Chat::conversations()->for($user)->limit(25)->page(1)->get();$users = $conversation->users;Chat is open-sourced software licensed under the MIT license