faraztanveer/laravel-chat

This is my package laravel-chat

v1.0.3 2025-06-04 10:37 UTC

This package is auto-updated.

Last update: 2025-06-16 01:32:56 UTC


README

Latest Version Downloads Monthly Downloads GitHub Stars GitHub Forks Code Style PHP Version Laravel Version License Last Commit Made with Love

πŸš€ A blazingly fast, modern chat system for Laravel 12+

Built for real-time applications, infinite customization, and developer happiness

πŸ“¦ Installation β€’ ✨ Features β€’ βš™οΈ Quick Start β€’ πŸ“‘ API Reference β€’ 🀝 Contributing

✨ Features

🎯 Zero Configuration

  • Works out of the box with sensible defaults
  • Auto-discovered database migrations
  • No complex setup required

⚑ Lightning Fast

  • Optimized database queries
  • Minimal performance overhead
  • Ready for real-time implementations

πŸ”§ Fully Customizable

  • Use your existing models and rules
  • Extend functionality as needed
  • Clean, simple architecture

πŸ›‘οΈ Enterprise Ready

  • Middleware-friendly design
  • Configurable API routes
  • Production-tested and reliable

πŸ’‘ Perfect for: Chat applications, messaging systems, customer support platforms, team collaboration tools, and any real-time communication needs.

πŸš€ Installation

# Install the package
composer require faraztanveer/laravel-chat

# Run migrations
php artisan migrate
πŸ“¦ Optional: Publish configuration file
php artisan vendor:publish --provider="Faraztanveer\LaravelChat\LaravelChatServiceProvider" --tag=config

βš™οΈ Quick Start

1️⃣ Setup Your User Model

Add the HasChatChannels trait to your user model:

<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Faraztanveer\LaravelChat\Traits\HasChatChannels;

class User extends Authenticatable
{
    use HasChatChannels;
    
    // Your existing code...
}

2️⃣ Start Chatting!

That's it! Your application now has a fully functional chat system. The package provides RESTful API endpoints for all chat operations.

πŸŽ›οΈ Configuration

The package works seamlessly out of the box, but you can customize it to fit your needs.

Configuration file (config/laravel-chat.php):

<?php

return [
    // Your participant model (usually User model)
    'participant_model' => App\Models\User::class,
    
    // API route customization
    'route_prefix' => 'chat',                    // Routes: /api/chat/*
    'route_middleware' => ['auth:sanctum'],      // Authentication middleware
];

πŸ“‘ API Reference

All endpoints are available under /api/{route_prefix} (default: /api/chat).

Method Endpoint Description Request Body/Parameters
POST /channel Create or retrieve a chat channel {"participant_id": 2}
GET /channels List user's chat channels –
GET /channel Get specific channel details ?channel_id=1
POST /message Send a message to channel {"channel_id": 1, "body": "Hello!"}
GET /messages Retrieve channel messages ?channel_id=1

Example Usage

// Create or get a chat channel
const response = await fetch('/api/chat/channel', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer your-token'
    },
    body: JSON.stringify({
        participant_id: 2
    })
});

// Send a message
await fetch('/api/chat/message', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer your-token'
    },
    body: JSON.stringify({
        channel_id: 1,
        body: "Hello there!"
    })
});

🎨 Customization

Custom Display Names

Override the display name for chat participants:

class User extends Authenticatable
{
    use HasChatChannels;
    
    public function getChatDisplayName(): string
    {
        return $this->full_name ?? $this->name;
    }
}

Custom Participant Columns

Specify which columns to include in API responses:

class User extends Authenticatable
{
    use HasChatChannels;
    
    public function chatParticipantColumns(): array
    {
        return ['id', 'name', 'email', 'avatar_url'];
    }
}

Middleware Customization

You can customize authentication and authorization middleware in the configuration file:

// config/laravel-chat.php
return [
    'route_middleware' => ['auth:sanctum', 'verified', 'custom-middleware'],
];

🀝 Contributing

We welcome contributions! Here's how you can help make Laravel Chat even better:

πŸ›‘οΈ Security

Security is a top priority. If you discover any security-related issues, please email faraz.io@outlook.com instead of using the issue tracker.

See SECURITY.md for our security policy and vulnerability reporting process.

πŸ“‹ Requirements

  • PHP 8.2+
  • Laravel 12.0+
  • Database (MySQL, PostgreSQL, SQLite, SQL Server)

πŸ—ΊοΈ Roadmap

  • File attachment support
  • Message reactions and emojis
  • Message threading
  • Advanced search functionality
  • Message encryption
  • Group chat management
  • Message status indicators (sent, delivered, read)

πŸ“œ License

This package is open-sourced software licensed under the MIT License.

πŸ‘¨β€πŸ’» Credits

Built with ❀️ for the Laravel community

⭐ Star this repository if it helped you!

πŸ› Report Bug β€’ πŸ’‘ Request Feature β€’ 🐦 X