sevenspan/laravel-chat
Composer 安装命令:
composer require sevenspan/laravel-chat
包简介
The Laravel Chat package simplifies one-to-one and group chat integration, facilitates document sharing within chats, manages read and unread message counts, and supports document uploads to both local and AWS S3 storage
关键字:
README 文档
README
The Laravel Chat package simplifies one-to-one chat integration facilitates document sharing within chats, manages read and unread message counts, and supports document uploads to both local and AWS S3 storage
Index
Prerequisites
Before you get started, make sure you have the following prerequisites installed:
- PHP >= 8.1 (Support 8.2)
- Composer >= 2.0
- Laravel >= 8.1 (Supports L10 and L11)
- AWS API credentials (Optional)
- Pusher
Features
- One-to-One Chat Integration
- Document Sharing within Chats
- Read and Unread Message Count Management
- Document Upload Support for Local Storage
- Document Upload Support for AWS S3 Storage
- Message body encryption and decryption
Installation
To install this package, use Composer:
composer require sevenspan/laravel-chat
Configurations
To configure the package, publish the migration file with the following command:
php artisan vendor:publish --provider="SevenSpan\Chat\Providers\ChatServiceProvider"
This command will publish the configuration file chat.php to your project's config directories, respectively.
If you have cached configurations locally, clear the config cache using one of these commands:
php artisan optimize:clear
After publishing the migration and configuring, create the required tables for this package by running:
php artisan migrate
To configure message body encryption add these key on .env file.
CHAT_ENCRYPT_MESSAGE=true #boolean
Usage
Once you have installed the package, you can start using its features in your Laravel application. Here's a brief overview of how to use some of the main features:
1. List Channels
Use the list method to get all channels.
use SevenSpan\Chat\Facades\Channel; // $userId = 12; (Required) // $channelIds = [1, 2, 3]; (Optional) // $perPage = 10; (Optional) Channel::list($userId, $channelIds, $perPage);
2. Detail of Channel
Use the detail method to get the detail of channel.
use SevenSpan\Chat\Facades\Channel; // $userId = 12; (Required) // $channelId = 10; (Required) Channel::detail($userId, $channelId);
3. Create Channel
Use the create method to create the new channel.
use SevenSpan\Chat\Facades\Channel; // $userId = 12; (Required) // $receiverId = 10; (Required) // $channelName = "Goverment project" (Required) Channel::create($userId, $receiverId, $channelName);
4. Update Channel
Use the update method to update the channel details.
use SevenSpan\Chat\Facades\Channel; // $userId = 12; (Required) // $receiverId = 10; (Required) // $channelName = "Goverment project" (Required) Channel::update($userId, $receiverId, $channelName);
5. Delete Channel
Use the delete method to delete the channel.
use SevenSpan\Chat\Facades\Channel; // $userId = 12; (Required) // $channelId = 10; (Required) Channel::delete($userId, $channelId);
6. Clear Channel History
Use the clearMessage method to clear the chat history.
use SevenSpan\Chat\Facades\Channel; // $userId = 1; (Required) // $channelId = 1 (Required) Channel::clearMessage($userId, $channelId);
7. List Message
Use the list method to get all messages of the channel.
use SevenSpan\Chat\Facades\Message; // $userId = 1; (Required) // $channelId = 1 (Required) // $perPage = 10; (Optional) Message::list($userId, $channelId, $perPage);
8. Send Message
Use the send method to send a message.
use SevenSpan\Chat\Facades\Message; // $userId = 1; (Required) // $channelId = 1 (Required) // $data = [ // 'body' => 'TEXT_MESSAGE', // 'file' => Image Or Document // ]; (Required) Message::send($userId, $channelId, $data);
Note
In the $data param either body or file is required.
9. Get Files Message
Use the getFiles method to document of the channel.
use SevenSpan\Chat\Facades\Message; // $userId = 1; (Required) // $channelId = 1 (Required) // $type = 'image' (Default: image) // $perPage = 10; (Optional) Message::getFiles($userId, $channelId, $type, $perPage);
Note
$type param supported value is image or zip.
10. Delete Message
Use the delete method to delete the message.
use SevenSpan\Chat\Facades\Message; // $userId = 1; (Required) // $channelId = 1 (Required) // $messageId = 10; (Required) Message::delete($userId, $channelId, $messageId);
11. Read Message
Use the read method to read the message of a channel.
use SevenSpan\Chat\Facades\Message; // $userId = 1; (Required) // $channelId = 1 (Required) // $messageId = 10; (Required) Message::read($userId, $channelId, $messageId);
Note
The messages that have a lesser value than $messageId will be read automatically.
12. User List
Use the list method to get a list of users and also search for the name of the user.
use SevenSpan\Chat\Facades\User; // $userId = 1; (Required) // $name = "John Doe" (Optional) // $perPage = 10; (Optional) User::list($userId, $name, $perPage);
Credits
Contributing
If you encounter any issues or would like to contribute to this package, we welcome contributions from the community to improve and enhance this package. If you'd like to contribute, please follow our contribution guidelines:
- Fork this repository.
- Clone the forked repository to your local machine.
- Create a new branch for your feature or bug fix: git checkout -b feature/your-feature-name
- Make your changes and commit them: git commit -m 'Add new feature'
- Push your changes to your fork: git push origin feature/your-feature-name
- Create a pull request to the original repository.
License
This package is open-source software licensed under the MIT License. Feel free to use, modify, and distribute it according to the terms of the license.
sevenspan/laravel-chat 适用场景与选型建议
sevenspan/laravel-chat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 241 次下载、GitHub Stars 达 18, 最近一次更新时间为 2023 年 10 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「composer」 「chat」 「laravel」 「chat-system」 「chat-package」 「chat-application」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sevenspan/laravel-chat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sevenspan/laravel-chat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sevenspan/laravel-chat 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This simple PHP class allows you to easily generate Smartsupp.com JS chat code.
Client for the REST API plugin of the OpenFire Server
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
Simple ASCII output of array data
统计信息
- 总下载量: 241
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-18