unseen-codes/chat 问题修复 & 功能扩展

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

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

unseen-codes/chat

Composer 安装命令:

composer require unseen-codes/chat

包简介

A plug-and-play Livewire chat system for Laravel

README 文档

README

A plug-and-play Livewire single-file chat component for Laravel.

Laravel Livewire PHP

What you get

  • Single-file Livewire component — drop <livewire:chat-box> anywhere
  • 1-on-1 and group conversations
  • Emoji reactions (toggle on/off)
  • Reply threading
  • File attachments
  • Read receipts (✓✓)
  • Typing indicator
  • Inline message editing
  • Soft-deleted messages
  • Config-driven — toggle every feature, swap every model
  • No controller needed — all wire: directives

Requirements

Package Version
PHP 8.2+
Laravel 11, 12, or 13
Livewire 3 or 4

Installation

1. Install the package

composer require unseen-codes/chat

2. Publish config

php artisan vendor:publish --tag=chat-config

3. Publish and run migrations

php artisan vendor:publish --tag=chat-migrations
php artisan migrate

4. Add Chattable trait to your User model

// app/Models/User.php
use UnseenCodes\Chat\Traits\Chattable;

class User extends Authenticatable
{
    use Chattable;
}

Usage

Start a conversation (in any route/page)

// routes/web.php — no controller needed with Livewire/Volt pages
Route::get('/chat/{user}', function (User $user) {
    $conversation = auth()->user()->chatWith($user);
    return view('chat', compact('conversation'));
})->middleware('auth');

Or using the service directly

use UnseenCodes\Chat\Contracts\ChatManagerContract;

$chat = app(ChatManagerContract::class);

// 1-on-1
$conversation = $chat->findOrCreatePrivateConversation($alice, $bob);

// Group
$conversation = $chat->createGroupConversation('Team Chat', $alice, [$bob, $charlie]);

Drop the component in any Blade view

{{-- resources/views/chat.blade.php --}}
<div class="h-[600px]">
    <livewire:chat-box :conversation="$conversation" />
</div>

That's it. No controller. No extra routes. The component handles everything.

Using Volt single-file pages

If you want the whole chat page as a Volt single file:

php artisan make:volt chat/show --class
{{-- resources/views/livewire/chat/show.blade.php --}}
<?php

use Livewire\Component;
use App\Models\User;
use UnseenCodes\Chat\Contracts\ChatManagerContract;

new class extends Component {

    public $conversation;

    public function mount(User $user): void
    {
        $this->conversation = app(ChatManagerContract::class)
            ->findOrCreatePrivateConversation(auth()->user(), $user);
    }

    public function render()
    {
        return view('livewire.chat.show');
    }
}
?>

<div class="h-screen p-4">
    <livewire:chat-box :conversation="$conversation" />
</div>

Route it:

// Livewire 4
Route::livewire('/chat/{user}', 'chat.show')->middleware('auth');

// Livewire 3
Route::get('/chat/{user}', \App\Livewire\Chat\Show::class)->middleware('auth');

Chattable trait helpers

// Start or resume a 1-on-1 chat
$conversation = $alice->chatWith($bob);

// Create a group
$conversation = $alice->startGroupChat('Dev Team', [$bob, $charlie]);

// Get all conversations (sorted by latest activity)
$conversations = $alice->conversations;

// Total unread count
$unread = $alice->unreadMessageCount();

// Unread in a specific conversation
$unread = $alice->unreadCountIn($conversation);

Config reference — config/chat.php

// Swap any model
'models' => [
    'message' => \App\Models\Chat\Message::class, // extend the base model
],

// Toggle features — disabled = hidden from UI + skipped in logic
'features' => [
    'attachments'      => true,
    'reactions'        => true,
    'read_receipts'    => true,
    'typing_indicator' => true,
    'group_chat'       => true,
    'message_editing'  => true,
],

// Disable broadcasting → falls back to wire:poll (no WebSocket needed)
'broadcasting' => [
    'enabled' => env('CHAT_BROADCASTING_ENABLED', false),
],

Publish views to customize

php artisan vendor:publish --tag=chat-views

Views land in resources/views/vendor/chat/livewire/chat-box.blade.php. Edit freely — the package uses your file automatically.

Enable real-time broadcasting (optional)

Install Reverb (ships with Laravel 11+):

php artisan install:broadcasting

Update .env:

BROADCAST_DRIVER=reverb
CHAT_BROADCASTING_ENABLED=true

Add channel auth to routes/channels.php:

use UnseenCodes\Chat\Models\Conversation;
use UnseenCodes\Chat\Contracts\ChatManagerContract;

Broadcast::channel('conversation.{conversationId}', function ($user, $conversationId) {
    $conversation = Conversation::find($conversationId);
    return $conversation
        && app(ChatManagerContract::class)->isParticipant($user, $conversation);
});

Without broadcasting the component auto-falls back to wire:poll.5s — works fine for most apps.

Overriding a model

// app/Models/Chat/Message.php
namespace App\Models\Chat;

use UnseenCodes\Chat\Models\Message as BaseMessage;

class Message extends BaseMessage
{
    public function isFlagged(): bool
    {
        return (bool) ($this->meta['flagged'] ?? false);
    }
}

Then in config/chat.php:

'models' => [
    'message' => \App\Models\Chat\Message::class,
],

Seeder (optional demo data)

use UnseenCodes\Chat\Contracts\ChatManagerContract;
use UnseenCodes\Chat\Contracts\MessageServiceContract;

$chat = app(ChatManagerContract::class);
$msgs = app(MessageServiceContract::class);

$conv = $chat->createPrivateConversation($alice, $bob);
$msgs->send($conv, $alice, 'Hey Bob!');
$msgs->send($conv, $bob, 'Hey Alice!');

License

MIT © Unseen Codes

unseen-codes/chat 适用场景与选型建议

unseen-codes/chat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 22
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 40
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-11