roundly-consulting / messages-for-laravel
Realtime messages between entities using Laravel broadcasting
Package info
github.com/roundly-consulting/messages-for-laravel
pkg:composer/roundly-consulting/messages-for-laravel
Fund package maintenance!
Requires
- php: ^8.4
- illuminate/broadcasting: ^12.0|^13.0
- illuminate/contracts: ^12.0|^13.0
- illuminate/notifications: ^12.0|^13.0
- roundly-consulting/enums-for-laravel: ^1.0
- roundly-consulting/media-library-for-laravel: ^1.0
- roundly-consulting/package-toolkit-for-laravel: ^1.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.4
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.1
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- roundly-consulting/testing-for-laravel: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Messages for Laravel
A direct-message and group-chat foundation for any Laravel app. Give any Eloquent model a one-line messaging API with read receipts, unread counts, roles and attachments, react to plain Laravel events, and optionally broadcast threads, messages and typing in real time.
Installation
Requires PHP 8.4 and Laravel 12 or 13.
composer require roundly-consulting/messages-for-laravel php artisan vendor:publish --tag="media-migrations" php artisan vendor:publish --tag="messages-migrations" php artisan migrate
Publish both tags: every send reads the bundled media-library's media table. If your
participating models (usually User) have UUID/ULID keys, set MESSAGES_KEY_TYPE=uuid (or
ulid) before migrating.
Usage
Let a model take part in conversations:
use Illuminate\Database\Eloquent\Model; use RoundlyConsulting\Messages\Concerns\HasMessaging; use RoundlyConsulting\Messages\Interfaces\ParticipatesInMessaging; class User extends Model implements ParticipatesInMessaging { use HasMessaging; public function participateAs(): array { return ['id' => $this->id, 'name' => $this->name]; } }
Then start conversations, send, and track what is unread:
use RoundlyConsulting\Messages\Facades\Messages; $thread = Messages::start('Launch') ->withParticipants([$alice, $bob]) // $alice, the first, owns the group thread ->create(); Messages::to($thread)->from($alice)->send('Hello'); $dm = Messages::direct($alice, $bob); // one DM per pair, found or created Messages::send($dm, $bob, 'Hi Alice!'); Messages::unreadCount($bob); // 1 Messages::markRead($thread, $bob); Messages::inboxFor($bob, perPage: 20); // newest activity first, unread counts loaded
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/messages-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
Support our work
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
License
The MIT License (MIT). See LICENSE.md.