ronasit/laravel-chat 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ronasit/laravel-chat

Composer 安装命令:

composer require ronasit/laravel-chat

包简介

This package implements chat functionality based on push notifications.

关键字:

README 文档

README

Coverage Status

Table of Contents

Introduction

This plugin adds the ability for users to work with chat functionalities in a Laravel application.

Installation

  1. Install the package using the following command:
composer require ronasit/laravel-chat
  1. Publish the package configuration:
php artisan vendor:publish --provider=RonasIT\\Chat\\ChatServiceProvider
  1. If you use non default App\Models\User model - update chat.classes.user_model config.

Integration with LaravelSwagger

This package includes an OpenAPI documentation file. To include it in your project's documentation, you need to register it in the auto-doc.additional_paths config:

vendor/ronasit/laravel-chat/documentation.json

API Endpoints

All routes are registered by default, you can change the route registration by calling Route::chat() in your routes file (e.g. routes/api.php).

  • feel free to call Route::chat() helper inside any route wrappers like group, prefix, etc. to wrap package routes; In this case default package's routes start to return 404.
  • calling Route::chat() without args will add all package routes inside the calling helper place;
  • calling Route::chat() with ChatRouteActionEnum cases as arguments will register only the specified routes — all others are automatically disabled:
// routes/api.php
use RonasIT\Chat\Enums\ChatRouteActionEnum;

Route::prefix('api')->group(function () {
    Route::middleware('auth_group')->group(function () {
        Route::chat(
            ChatRouteActionEnum::ConversationsSearch,
            ChatRouteActionEnum::MessageCreate,
        );
    });
});

All endpoints are using the current auth user context, so it critical to always wrap them into the auth middleware.

Conversations

Method URL Description
GET /conversations List all conversations the authenticated user is a member of.
GET /conversations/{id} Retrieve a single conversation by its ID.
DELETE /conversations/{id} Delete a conversation.
GET /users/{userId}/conversation Get the private conversation between the authenticated user and the specified user.

Messages

Method URL Description
GET /messages List of messages related to the current user's conversations.
POST /messages Create a new message.
POST /messages/{id}/read-to Mark all messages in the target message's conversation as read up to the specified message ID.
POST /messages/{id}/pin Pin a message to its conversation.
POST /messages/{id}/unpin Unpin a message from its conversation.

Broadcast Events

The package uses Laravel's broadcasting system to notify conversation members in real time. All events are delivered over private channels named chat.{userId}, where {userId} is the ID of the recipient.

Channel Authorization

A user may listen on only his own private channel chat.{userId}. The channel is authorized when the authenticated user's ID matches {userId}.

Events

conversation.created

Sent to all conversation members except the creator when a new conversation is created.

This event is triggered when:

  • A new group conversation is created.
  • A private conversation is created implicitly (e.g., when a user sends the first message to another user via recipient_id).

Payload:

{
    "id": 1,
    "type": "private|group",
    "title": "string or null",
    "last_updated_at": "2024-01-01T00:00:00.000000Z",
    "created_at": "2024-01-01T00:00:00.000000Z",
    "last_message": { /* MessageResource */ }
}

conversation.updated

Sent to all conversation members when a conversation is modified.

This event is triggered when:

  • A conversation's properties (e.g., title, cover) are updated.
  • A new message is created (the conversation's last_updated_at is updated as a side effect).
  • A message is pinned or unpinned in the conversation.

Payload:

{
    "id": 1,
    "type": "private|group",
    "title": "string or null",
    "last_updated_at": "2024-01-01T00:00:00.000000Z",
    "created_at": "2024-01-01T00:00:00.000000Z",
    "last_message": { /* MessageResource */ },
    "pinned_messages": [ /* MessageResource */ ],
    "members_count": 2,
    "unread_messages_count": 0
}

conversation.deleted

Sent to all conversation members except the user who deleted it when a conversation is removed.

This event is triggered when:

  • A conversation is deleted via DELETE /conversations/{id}.

Payload:

{
    "id": 1
}

message.created

Sent to all conversation members except the sender when a new message is posted.

This event is triggered when:

  • A message is created via POST /messages.

Payload:

{
    "id": 1,
    "text": "Hello!",
    "conversation_id": 1,
    "is_read": false,
    "created_at": "2024-01-01T00:00:00.000000Z",
    "updated_at": "2024-01-01T00:00:00.000000Z",
    "sender": { /* UserResource */ }
}

message.updated

Sent to all conversation members when the read status of one or more messages changes.

This event is triggered when:

  • A user marks messages as read via POST /messages/{id}/read-to.

Payload:

{
    "id": 1,
    "text": "Hello!",
    "conversation_id": 1,
    "is_read": true,
    "created_at": "2024-01-01T00:00:00.000000Z",
    "updated_at": "2024-01-01T00:00:00.000000Z",
    "sender": { /* UserResource */ }
}

Contributing

Thank you for considering contributing to the Laravel Chat plugin! The contribution guide can be found in the Contributing guide.

License

Laravel Chat plugin is open-sourced software licensed under the MIT license.

ronasit/laravel-chat 适用场景与选型建议

ronasit/laravel-chat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.38k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 08 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「chat」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ronasit/laravel-chat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ronasit/laravel-chat 我们能提供哪些服务?
定制开发 / 二次开发

基于 ronasit/laravel-chat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-10