Skip to content

A powerful and flexible chat system for Laravel applications with support for private conversations, group chats, real-time broadcasting, and advanced message management.

License

Notifications You must be signed in to change notification settings

Kareemsliet/chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💬 Laravel Chat

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

About

A powerful and flexible chat system for Laravel applications with support for private conversations, group chats, real-time broadcasting, and advanced message management.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages