finller / laravel-conversations
Attach chat to any model
Installs: 9 093
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 1
Requires
- php: ^8.1
- illuminate/contracts: ^10.0|^11.0
- spatie/laravel-package-tools: ^1.13.6
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8|^8.1
- orchestra/testbench: ^8.8|^9.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^10.0
- spatie/laravel-ray: ^1.26
README
This package the basic architecture of a chat between multiple users.
Installation
You can install the package via composer:
composer require finller/laravel-conversations
You can publish and run the migrations with:
php artisan vendor:publish --tag="conversations-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="conversations-config"
This is the contents of the published config file:
return [ /** * The Model used with the user_id and owner_id */ 'model_user' => User::class, 'model_message' => Message::class, 'model_conversation' => Conversation::class, /** * When a User is deleted, his messages will be deleted */ 'cascade_user_delete_to_messages' => false, /** * When a User is deleted, his messages will be deleted */ 'cascade_conversation_delete_to_messages' => false, /** * When the parent of a conversation is deleted, the conversation is deleted */ 'cascade_conversationable_delete_to_conversation' => false, ];
Usage
1. Create the conversation
$conversation = new Conversation(); $conversation->conversationable()->associate($mission); // optional $conversation->save(); $conversation->users()->sync($usersIds);
2. Save messages in the conversation
$message = new Message([ 'content' => "My message", ]); $message->user()->associate($this->user); $this->conversation->messages()->save($message);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.