Download the PHP package martinko366/laravel-db-chat without Composer
On this page you can find all versions of the php package martinko366/laravel-db-chat. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download martinko366/laravel-db-chat
More information about martinko366/laravel-db-chat
Files in martinko366/laravel-db-chat
Package laravel-db-chat
Short Description A database-driven chat package for Laravel with long-polling support
License MIT
Informations about the package laravel-db-chat
Laravel DB Chat
A database-driven chat package for Laravel with long-polling support. No Redis, Pusher, or external services required - everything runs on your existing database.
Features
- ✅ Pure Database Solution - No external services needed
- ✅ Direct & Group Chats - Support for 1:1 and group conversations
- ✅ Long Polling - Realtime-ish updates without WebSockets
- ✅ Read Receipts - Track who has seen which messages
- ✅ Cursor-based Polling - Efficient message fetching using monotonic IDs
- ✅ Rate Limiting - Built-in protection against abuse
- ✅ Laravel 10, 11 & 12 - Compatible with modern Laravel versions
Installation
Install the package via Composer:
Publish the configuration and migrations:
Run the migrations:
Configuration
The package configuration file is located at config/dbchat.php. You can customize:
- Database table names
- User model
- Route prefix and middleware
- Polling timeout and intervals
- Rate limits
- Message length limits
Usage
Authentication
The package uses Laravel Sanctum by default. Ensure you have authentication configured:
API Endpoints
All endpoints are prefixed with /api/dbchat by default.
Create a Conversation
POST /api/dbchat/conversations
For group chats:
Response:
List Conversations
GET /api/dbchat/conversations
Returns all conversations for the authenticated user.
Get Conversation Details
GET /api/dbchat/conversations/{id}
Send a Message
POST /api/dbchat/conversations/{id}/messages
Response:
Get Messages
GET /api/dbchat/conversations/{id}/messages?before_message_id=100&limit=50
Fetch historical messages with pagination.
Long Polling for New Messages
GET /api/dbchat/poll?after_message_id=523
This endpoint will wait up to 25 seconds (configurable) for new messages. Returns:
200with new messages if available204 No Contentif no new messages before timeout
Response (200):
Mark Message as Read
POST /api/dbchat/messages/{id}/read
Returns 204 No Content on success.
Client Implementation Example
Here's a simple JavaScript client for long polling:
Vue/React Component Example
Here's a basic Vue 3 composition example:
How It Works
The Polling Mechanism
- Client keeps track of
lastMessageId(starts at 0) - Client calls
/poll?after_message_id=X - Server queries for messages with
id > X - If messages exist, return immediately
- If no messages, wait up to 25 seconds, checking every 500ms
- Return
204 No Contentif timeout reached - Client updates
lastMessageIdand polls again
Database Schema
conversations
- id, type (direct/group), title, timestamps
participants
- id, conversation_id, user_id, joined_at, timestamps
- Unique index on (conversation_id, user_id)
messages
- id (auto-increment), conversation_id, sender_id, body, attachments, timestamps
- Index on (conversation_id, id) for efficient polling
message_reads
- id, message_id, user_id, read_at
- Unique index on (message_id, user_id)
Performance Tips
- The package uses indexed queries with monotonic IDs for efficient polling
- Direct conversations are deduplicated automatically
- Use the
before_message_idparameter for pagination - Configure rate limits based on your needs
- Adjust polling timeout and check interval for your use case
Environment Variables
Advanced: SSE (Server-Sent Events)
If you prefer SSE over long polling, you can create a custom controller:
Testing
Security
- All routes are protected by authentication middleware
- Users can only access conversations they're participants in
- Rate limiting prevents abuse
- Input validation on all endpoints
License
MIT License
Credits
Created by Martinko366
Support
For issues and questions, please use the GitHub issue tracker.
All versions of laravel-db-chat with dependencies
illuminate/support Version ^10.0|^11.0
illuminate/database Version ^10.0|^11.0
illuminate/http Version ^10.0|^11.0