finller / laravel-conversations
将聊天附加到任何模型
v0.5.3
2024-08-13 16:25 UTC
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
此包提供了多用户间聊天的基本架构。
安装
您可以通过composer安装此包
composer require finller/laravel-conversations
您可以使用以下命令发布和运行迁移
php artisan vendor:publish --tag="conversations-migrations"
php artisan migrate
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="conversations-config"
这是发布配置文件的内容
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, ];
用法
1. 创建聊天
$conversation = new Conversation(); $conversation->conversationable()->associate($mission); // optional $conversation->save(); $conversation->users()->sync($usersIds);
2. 在聊天中保存消息
$message = new Message([ 'content' => "My message", ]); $message->user()->associate($this->user); $this->conversation->messages()->save($message);
测试
composer test
变更日志
请参阅变更日志以获取有关最近更改的更多信息。
贡献
请参阅贡献指南以获取详细信息。
安全漏洞
请查看我们的安全策略了解如何报告安全漏洞。
鸣谢
许可
MIT许可(MIT)。请参阅许可文件以获取更多信息。