PHPackages                             saritasa/laravel-chat-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. saritasa/laravel-chat-api

AbandonedArchivedLibrary[API Development](/categories/api)

saritasa/laravel-chat-api
=========================

Classes, that implement chat API on top of laravel

2.0.0(8y ago)20834MITPHPPHP &gt;=7.1

Since Apr 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Saritasa/php-laravel-chat-api)[ Packagist](https://packagist.org/packages/saritasa/laravel-chat-api)[ RSS](/packages/saritasa-laravel-chat-api/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (7)Versions (3)Used By (0)

[![PHP Unit](https://github.com/Saritasa/php-laravel-chat-api/workflows/PHP%20Unit/badge.svg)](https://github.com/Saritasa/php-laravel-chat-api/actions)[![PHP CodeSniffer](https://github.com/Saritasa/php-laravel-chat-api/workflows/PHP%20Codesniffer/badge.svg)](https://github.com/Saritasa/php-laravel-chat-api/actions)[![codecov](https://camo.githubusercontent.com/c423c191052da6fe809f9175c2a7a67ef58a78f766f400af287f9f76eea97b1d/68747470733a2f2f636f6465636f762e696f2f67682f53617269746173612f7068702d6c61726176656c2d636861742d6170692f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/Saritasa/php-laravel-chat-api)

Laravel Chat Api
================

[](#laravel-chat-api)

Adds chat functionality for your project on top of Laravel [Broadcasting](https://laravel.com/docs/broadcasting) feature.

Laravel 5.5+
------------

[](#laravel-55)

Lower versions are not supported.

### Installation and configuration Install the `saritasa/laravel-chat-api` package:

[](#installation-and-configuration-install-the-saritasalaravel-chat-api-package)

`bash $ composer require saritasa/laravel-chat-api `Publish config with
`bash $ artisan vendor:publish --tag=laravel_chat_api `Update config/laravel\_chat\_api.php sections:

- Implement IChatUser contract to your application user model and update parameter `userModelClass`.
- Check notifications section and add your own notification instead this mocks.

Configure at least one [broadcasting driver](https://laravel.com/docs/broadcasting#driver-prerequisites)

Work with service Add IChatService contract injection in needed class.
----------------------------------------------------------------------

[](#work-with-service-add-ichatservice-contract-injection-in-needed-class)

### Methods: - Create chat

[](#methods---create-chat)

```
 $chatService->createChat($creator, ['name' => 'New Chat'], [1, 2]);
```

Where \[1, 2\] - identifiers of participants of chat excluded creator.

- Close chat

```
 $chatService->closeChat($creator, $chat);
```

Remember that only creator can close chat and can't close "already closed" chat. In this cases ChatException will be
thrown.

- Leave chat

```
 $chatService->leaveChat($user, $chat);
```

When creator leaves chat on of participants became to creator.

- Send message in chat

```
 $chatService->sendMessage($sender, $chat, $message);
```

- Mark chat as read

```
 $chatService->markChatAsRead($chat, $user);
```

### Events:

[](#events)

Chat events:
------------

[](#chat-events)

Throws in chat channel for all subscribers who participate in chatting.

- MessageSentEvent throws when participant sent new message in chat.
- ChatLeavedEvent throws when one of participants leaved this chat.
- ChatClosedEvent throws when creator closed this chat.

User events:
------------

[](#user-events)

Throws in user channel for all subscribers who participate in chatting exclude event initiator.

- ChatCreatedEvent throws when user created new chat.
- MessageSentEvent throws when participant sent new message in chat.
- ChatClosedUserEvent throws when creator closed this chat.
- ChatReopenedUserEvent throws when creator reopened closed chat.

Broadcasting settings:
----------------------

[](#broadcasting-settings)

To integrate it with Laravel broadcasting you can just update your broadcasting routes file ( routes/channels.php by default ) with next example:

```
...
use Saritasa\LaravelChatApi\Events\ChatCreatedEvent;
use Saritasa\LaravelChatApi\Events\ChatEvent;
use Saritasa\LaravelChatApi\Contracts\IChatUser;
...
// Using model binding for chat events channel.
Broadcast::channel(ChatEvent::CHANNEL_PREFIX . '{chat}', function ($user, Chat $chat) {
  // Checking that auth user is chat participant.
  return $chat->getUsers()->pluck('id')->contains($user->id);
});

Broadcast::channel(ChatCreatedEvent::CHANNEL_PREFIX . '{id}', function ($user, int $id) {
  return (int)$user->id === $id;
});
```

Read in official [documentation](https://laravel.com/docs/broadcasting#defining-authorization-callbacks) about defining authorization callbacks. **Now all chat events will dispatch through your broadcast driver.**

Notifications settings:
-----------------------

[](#notifications-settings)

To easy sent notifications you should create your own [notification](https://laravel.com/docs/notifications#creating-notifications) and update `laravel_chat_api.php` config file. **Here is example if we should send notification when chat was reopened:**

```
return [
	...
	'notifications' => [
	   ...
	  'chatReopened' => App\Notifications\MyOwnChatReopenedNotification::class,
	],
];
```

Contributing
------------

[](#contributing)

1. Create fork
2. Checkout fork
3. Develop locally as usual. **Code must follow [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/)**
4. Update README.md to describe new or changed functionality. Add changes description to CHANGE file.
5. When ready, create pull request

Resources
---------

[](#resources)

- [Bug Tracker](http://github.com/saritasa/php-laravel-chat-api/issues)
- [Code](http://github.com/saritasa/php-laravel-chat-api)

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~436 days

Total

2

Last Release

2930d ago

Major Versions

1.0.0 → 2.0.02018-06-22

PHP version history (2 changes)1.0.0PHP &gt;=7.0

2.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/b7632cf2eb5dd552ace9d66947ed6919e19c6a2fdb5dc73b8c71e0f9886ccc83?d=identicon)[saritasa](/maintainers/saritasa)

---

Top Contributors

[![maxermolenko](https://avatars.githubusercontent.com/u/11438109?v=4)](https://github.com/maxermolenko "maxermolenko (6 commits)")[![populov](https://avatars.githubusercontent.com/u/3766033?v=4)](https://github.com/populov "populov (4 commits)")[![hollow-en](https://avatars.githubusercontent.com/u/87475798?v=4)](https://github.com/hollow-en "hollow-en (1 commits)")[![veeeeeRySeXy](https://avatars.githubusercontent.com/u/10694924?v=4)](https://github.com/veeeeeRySeXy "veeeeeRySeXy (1 commits)")

---

Tags

apichatlaravelphpapilaravelchat

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/saritasa-laravel-chat-api/health.svg)

```
[![Health](https://phpackages.com/badges/saritasa-laravel-chat-api/health.svg)](https://phpackages.com/packages/saritasa-laravel-chat-api)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

815320.5k3](/packages/defstudio-telegraph)[resend/resend-laravel

Resend for Laravel

1212.2M8](/packages/resend-resend-laravel)[essa/api-tool-kit

set of tools to build an api with laravel

53386.5k](/packages/essa-api-tool-kit)[api-platform/laravel

API Platform support for Laravel

59156.3k11](/packages/api-platform-laravel)[simplestats-io/laravel-client

Analytics for Laravel. Track visitors, registrations, and payments. Discover which channels actually drive revenue, not just traffic. Server-side, GDPR compliant, ad-blocker proof.

5019.3k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
