metko / galera
Messaging/chatting package for laravel
Requires (Dev)
- matthewbdaly/artisan-standalone: dev-master
- mockery/mockery: ~1.0
- orchestra/testbench: ^3.7
- orchestra/testbench-browser-kit: ^3.7
- php-coveralls/php-coveralls: ^2.1
- phpstan/phpstan: ^0.10.5
- phpunit/phpunit: ^7.0
- psy/psysh: ^0.9.8
- sebastian/phpcpd: ^4.0
- squizlabs/php_codesniffer: ^3.3
This package is auto-updated.
Last update: 2025-02-06 14:23:11 UTC
README
Galera is small package to handle conversation between two or multiple user.
Installations
Step 1
composer require metko/galera
Step 2
Publish the config file and the asset
php artisan pusblish --tag:galera
How to use it
Usage
Use the trait
Use the trait Galerable in your user model
// Metko\Galera\Galerable; use Galerable;
Conversation
Create a conversation
Galera::participants($user1, $user2)->make(); *// Or pass an array of multiple user* Galera::addParticipants([1,2,3,'10'])->make();
Get a conversation
Galera::conversation($id); // Or with the messages Galera::conversation($id, true);
*Return a conversation with [‘messages_count’, ’unread_messages_count’] by default *
Clear a conversation
Galera::conversation($id)->clear();
Will soft delete all the message of the given conversation
Close a conversation
Galera::conversation($id)->close(); return Metko\Galera\Conversation
Nobody can submit a message in a close conversation
Check if a conversation is closed
Galera::conversation($id)->isCLosed(); // return bool
Add participants in a conversation
Galera::conversation($id)->add(1); // Or many user at the same time Galera::conversation($id)->addMany([1, $user2, '3']);
A Conversation can remove a participant
Galera::conversation($id)->remove(1);
A conversation must have at least 2 participants. It will return an error if you try to do it.
Read all message of a conversation
Galera::conversation($id)->readAll();
A conversation must have at least 2 participants. It will return an error if you try to do it.
User
A user can write a message
$user->write(‘My message’, $conversationId); // You can pass a model or an id for the conversation
Delete a message
Galera::message(1)->delete(); // You can pass a model or an id for the conversation param*
Write a message refering another
$user->write(‘My message’, $conversationId, $message->id); // You can pass a model or an id for the message param*
Check if a user has unread message on a specific conversation
$user->hasUnreadMessage($convzersationId); // Return bool //Or in all conversation where he is participant $user->hasUnreadMessage(); // Return bool
Get unread messages for user
$user->unreadMessages();
Read all the message unread for a user in a conversation
$user->readAll($convzersationId); // Return Collection
Return a list of all conversation ordered by updated_at, count of message, and unread_message_count
Get the last conversation of a user
$user->getLastConversation($withMessage = false, $nbMessage = 25); // Return Collection
Return a list of all conversation ordered by updated_at, count of message, and unread_message_count
Messagess
Get messages from a conversation
Galera::ofConversation($conversationId)->get();
Get a unread_message count in conversation
Galera::conversation($id)->unread_messages_count;
Get a total_message count n conversation
Galera::conversation($id)->messages_count;
Test cases
The package includes three test cases:
TestCase
- Effectively the normal Laravel test case. Use it the same way you would your normal Laravel test caseSimpleTestCase
- Extends the default PHPUnit test case, so it doesn’t set up a Laravel application, making it quicker and well-suited to properly isolated unit testsBrowserKitTestCase
- Sets up BrowserKit