ronasit / laravel-chat
This package implements chat functionality based on push notifications.
Requires
- php: ^8.3
- laravel/framework: >=12
- ronasit/laravel-helpers: >=3.7
- ronasit/laravel-media: >=0.2
Requires (Dev)
- laravel/pint: ^1.27
- orchestra/testbench: >=9.3
- phpunit/php-code-coverage: ^11.0
- phpunit/phpunit: >=11.5
- dev-master
- 0.3.2
- 0.3.1
- 0.3
- 0.2
- 0.1.8-beta
- 0.1.7-beta
- 0.1.6-beta
- 0.1.5-beta
- 0.1.4-beta
- 0.1.3-beta
- 0.1.2-beta
- 0.1.1-beta
- 0.1-beta
- 0.0.6-beta
- 0.0.5-beta
- 0.0.4-beta
- 0.0.3-beta
- 0.0.2-beta
- 0.0.1.2-beta
- 0.0.1.1-beta
- 0.0.1-beta
- dev-PRD-2238/title-and-cover-for-private-conversations-from-the-other-participant
- dev-yburlakov/action
- dev-61-add-order-by-validation-using-config
- dev-86_Add-sorting-orderBy('id')-to-hasMany-and-belongsToMany-model-relationships
- dev-86c86krgq_Extend-chat-to-work-with-multi-member-chats
This package is auto-updated.
Last update: 2026-05-22 06:57:55 UTC
README
Table of Contents
- Introduction
- Installation
- Integration with LaravelSwagger
- API Endpoints
- Broadcast Events
- Contributing
- License
Introduction
This plugin adds the ability for users to work with chat functionalities in a Laravel application.
Installation
- Install the package using the following command:
composer require ronasit/laravel-chat
- Publish the package configuration:
php artisan vendor:publish --provider=RonasIT\\Chat\\ChatServiceProvider
- If you use non default
App\Models\Usermodel - updatechat.classes.user_modelconfig.
Integration with LaravelSwagger
This package includes an OpenAPI documentation file. To include it in your project's documentation, you need to register it in the auto-doc.additional_paths config:
vendor/ronasit/laravel-chat/documentation.json
API Endpoints
All routes are registered by default, you can change the route registration by calling Route::chat() in your routes file (e.g. routes/api.php).
- feel free to call
Route::chat()helper inside any route wrappers likegroup,prefix, etc. to wrap package routes; In this case default package's routes start to return 404. - calling
Route::chat()without args will add all package routes inside the calling helper place; - calling
Route::chat()withChatRouteActionEnumcases as arguments will register only the specified routes — all others are automatically disabled:
// routes/api.php use RonasIT\Chat\Enums\ChatRouteActionEnum; Route::prefix('api')->group(function () { Route::middleware('auth_group')->group(function () { Route::chat( ChatRouteActionEnum::ConversationsSearch, ChatRouteActionEnum::MessageCreate, ); }); });
All endpoints are using the current auth user context, so it critical to always wrap them into the auth middleware.
Conversations
| Method | URL | Description |
|---|---|---|
GET |
/conversations |
List all conversations the authenticated user is a member of. |
GET |
/conversations/{id} |
Retrieve a single conversation by its ID. |
DELETE |
/conversations/{id} |
Delete a conversation. |
GET |
/users/{userId}/conversation |
Get the private conversation between the authenticated user and the specified user. |
Messages
| Method | URL | Description |
|---|---|---|
GET |
/messages |
List of messages related to the current user's conversations. |
POST |
/messages |
Create a new message. |
POST |
/messages/{id}/read-to |
Mark all messages in the target message's conversation as read up to the specified message ID. |
POST |
/messages/{id}/pin |
Pin a message to its conversation. |
POST |
/messages/{id}/unpin |
Unpin a message from its conversation. |
Broadcast Events
The package uses Laravel's broadcasting system to notify conversation members in real time. All events are delivered over private channels named chat.{userId}, where {userId} is the ID of the recipient.
Channel Authorization
A user may listen on only his own private channel chat.{userId}. The channel is authorized when the authenticated user's ID matches {userId}.
Events
conversation.created
Sent to all conversation members except the creator when a new conversation is created.
This event is triggered when:
- A new group conversation is created.
- A private conversation is created implicitly (e.g., when a user sends the first message to another user via
recipient_id).
Payload:
{
"id": 1,
"type": "private|group",
"title": "string or null",
"last_updated_at": "2024-01-01T00:00:00.000000Z",
"created_at": "2024-01-01T00:00:00.000000Z",
"last_message": { /* MessageResource */ }
}
conversation.updated
Sent to all conversation members when a conversation is modified.
This event is triggered when:
- A conversation's properties (e.g., title, cover) are updated.
- A new message is created (the conversation's
last_updated_atis updated as a side effect). - A message is pinned or unpinned in the conversation.
Payload:
{
"id": 1,
"type": "private|group",
"title": "string or null",
"last_updated_at": "2024-01-01T00:00:00.000000Z",
"created_at": "2024-01-01T00:00:00.000000Z",
"last_message": { /* MessageResource */ },
"pinned_messages": [ /* MessageResource */ ],
"members_count": 2,
"unread_messages_count": 0
}
conversation.deleted
Sent to all conversation members except the user who deleted it when a conversation is removed.
This event is triggered when:
- A conversation is deleted via
DELETE /conversations/{id}.
Payload:
{
"id": 1
}
message.created
Sent to all conversation members except the sender when a new message is posted.
This event is triggered when:
- A message is created via
POST /messages.
Payload:
{
"id": 1,
"text": "Hello!",
"conversation_id": 1,
"is_read": false,
"created_at": "2024-01-01T00:00:00.000000Z",
"updated_at": "2024-01-01T00:00:00.000000Z",
"sender": { /* UserResource */ }
}
message.updated
Sent to all conversation members when the read status of one or more messages changes.
This event is triggered when:
- A user marks messages as read via
POST /messages/{id}/read-to.
Payload:
{
"id": 1,
"text": "Hello!",
"conversation_id": 1,
"is_read": true,
"created_at": "2024-01-01T00:00:00.000000Z",
"updated_at": "2024-01-01T00:00:00.000000Z",
"sender": { /* UserResource */ }
}
Contributing
Thank you for considering contributing to the Laravel Chat plugin! The contribution guide can be found in the Contributing guide.
License
Laravel Chat plugin is open-sourced software licensed under the MIT license.