kareemsliet/chat
最新稳定版本:v1.0.0
Composer 安装命令:
composer require kareemsliet/chat
包简介
Chat Package for Laravel
README 文档
README
Modern chat package for Laravel with private conversations, group chats, and message management.
Features
- 💬 Private & group conversations
- 📨 Message management (send, edit, delete, reply)
- 🔔 Real-time broadcasting support (built-in)
- 👥 Participant roles (admin, member)
- 📌 Pin, favorite & star conversations
- 🆔 UUID support
Requirements
- PHP 8.1+
- Laravel 10.x | 11.x | 12.x
Installation
composer require kareemsliet/chat php artisan vendor:publish --tag=chat-migrations php artisan migrate
Setup
Add trait to your User model:
use kareemsliet\Chat\Traits\HasParticipant; class User extends Authenticatable { use HasParticipant; }
Quick Start
Create Conversations:
use kareemsliet\Chat\Facades\Chat; // Private conversation $conversation = Chat::privateWith($otherUser); // Group conversation $conversation = Chat::newGroup(['title' => 'Team Chat']);
Send Messages:
// Simple message $conversation->sendMessage("Hello!"); // With attachments $conversation->sendMessage("Check files", ['file.pdf', 'image.jpg']); // Reply to message $conversation->sendMessage("Thanks!", [], $messageId);
Manage Participants:
// Add/remove members $conversation->addMember($user); $conversation->addMembers([$user1, $user2]); $conversation->removeMember($user); // Change roles $conversation->makeAsAdmin($user); $conversation->makeAsMember($user);
Work with Messages:
// Get messages $messages = $conversation->messages(); $message = $conversation->messageById($id); // Message actions $message->markAsRead(); $message->star(); $message->edit("Updated content"); $message->delete();
Conversation Actions:
$conversation->pin(); $conversation->favorite(); $conversation->update(['title' => 'New Name']); $conversation->clear(); $conversation->delete();
Fetch Conversations:
$conversations = Chat::all(); $unread = Chat::unread(); $favorited = Chat::favorited(); $pinned = Chat::pinned(); $paginated = Chat::paginate(); $conversation = Chat::findById($id);
Events
Available events: MessageWasSent, MessageWasEdited, ConversationCreated, ConversationUpdated, ConversationCleared, ConversationLeft, ParticipantsJoined, ParticipantsLeft
Register listeners in EventServiceProvider:
protected $listen = [ \kareemsliet\Chat\Events\ConversationCreated::class => [ \App\Listeners\CreateConversation::class, ], ];
📖 Learn more: Laravel Events Documentation
Broadcasting
Enable real-time updates in config/chat.php:
'broadcasting' => [ 'enabled' => true, 'connection' => env('BROADCAST_CONNECTION', 'pusher'), ],
Listen to events:
// MessageWasSent - fires when message is sent Echo.private(`chat.conversations.${conversationId}`) .listen('MessageWasSent', (e) => { console.log(e.message); }); // MessageWasEdited - fires when message is edited Echo.private(`chat.conversations.${conversationId}`) .listen('MessageWasEdited', (e) => { console.log(e.message); });
📖 Learn more: Laravel Broadcasting Documentation
Configuration
Publish config file: php artisan vendor:publish --tag=chat-config
Key settings in config/chat.php:
- UUID support for conversations & messages
- Event broadcasting configuration
Testing
Testing suite under development.
Contributing
Contributions welcome! Submit a Pull Request.
License
MIT License. See LICENSE for details.
Support: GitHub Issues | Email: kareemoii37@gmail.com
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-03