unseen-codes/chat
Plug-and-play Livewire single-file chat component for Laravel. Drop livewire:chat-box anywhere for 1-on-1 or group chats with reactions, replies, attachments, read receipts, typing indicator, editing, soft deletes, and fully config-driven features/models.
A plug-and-play Livewire single-file chat component for Laravel.
<livewire:chat-box> anywhere| Package | Version |
|---|---|
| PHP | 8.2+ |
| Laravel | 11, 12, or 13 |
| Livewire | 3 or 4 |
composer require unseen-codes/chat
php artisan vendor:publish --tag=chat-config
php artisan vendor:publish --tag=chat-migrations
php artisan migrate
// app/Models/User.php
use UnseenCodes\Chat\Traits\Chattable;
class User extends Authenticatable
{
use Chattable;
}
// routes/web.php — no controller needed with Livewire/Volt pages
Route::get('/chat/{user}', function (User $user) {
$conversation = auth()->user()->chatWith($user);
return view('chat', compact('conversation'));
})->middleware('auth');
use UnseenCodes\Chat\Contracts\ChatManagerContract;
$chat = app(ChatManagerContract::class);
// 1-on-1
$conversation = $chat->findOrCreatePrivateConversation($alice, $bob);
// Group
$conversation = $chat->createGroupConversation('Team Chat', $alice, [$bob, $charlie]);
{{-- resources/views/chat.blade.php --}}
<div class="h-[600px]">
<livewire:chat-box :conversation="$conversation" />
</div>
That's it. No controller. No extra routes. The component handles everything.
If you want the whole chat page as a Volt single file:
php artisan make:volt chat/show --class
{{-- resources/views/livewire/chat/show.blade.php --}}
<?php
use Livewire\Component;
use App\Models\User;
use UnseenCodes\Chat\Contracts\ChatManagerContract;
new class extends Component {
public $conversation;
public function mount(User $user): void
{
$this->conversation = app(ChatManagerContract::class)
->findOrCreatePrivateConversation(auth()->user(), $user);
}
public function render()
{
return view('livewire.chat.show');
}
}
?>
<div class="h-screen p-4">
<livewire:chat-box :conversation="$conversation" />
</div>
Route it:
// Livewire 4
Route::livewire('/chat/{user}', 'chat.show')->middleware('auth');
// Livewire 3
Route::get('/chat/{user}', \App\Livewire\Chat\Show::class)->middleware('auth');
// Start or resume a 1-on-1 chat
$conversation = $alice->chatWith($bob);
// Create a group
$conversation = $alice->startGroupChat('Dev Team', [$bob, $charlie]);
// Get all conversations (sorted by latest activity)
$conversations = $alice->conversations;
// Total unread count
$unread = $alice->unreadMessageCount();
// Unread in a specific conversation
$unread = $alice->unreadCountIn($conversation);
// Swap any model
'models' => [
'message' => \App\Models\Chat\Message::class, // extend the base model
],
// Toggle features — disabled = hidden from UI + skipped in logic
'features' => [
'attachments' => true,
'reactions' => true,
'read_receipts' => true,
'typing_indicator' => true,
'group_chat' => true,
'message_editing' => true,
],
// Disable broadcasting → falls back to wire:poll (no WebSocket needed)
'broadcasting' => [
'enabled' => env('CHAT_BROADCASTING_ENABLED', false),
],
php artisan vendor:publish --tag=chat-views
Views land in resources/views/vendor/chat/livewire/chat-box.blade.php.
Edit freely — the package uses your file automatically.
Install Reverb (ships with Laravel 11+):
php artisan install:broadcasting
Update .env:
BROADCAST_DRIVER=reverb
CHAT_BROADCASTING_ENABLED=true
Add channel auth to routes/channels.php:
use UnseenCodes\Chat\Models\Conversation;
use UnseenCodes\Chat\Contracts\ChatManagerContract;
Broadcast::channel('conversation.{conversationId}', function ($user, $conversationId) {
$conversation = Conversation::find($conversationId);
return $conversation
&& app(ChatManagerContract::class)->isParticipant($user, $conversation);
});
Without broadcasting the component auto-falls back to wire:poll.5s — works fine for most apps.
// app/Models/Chat/Message.php
namespace App\Models\Chat;
use UnseenCodes\Chat\Models\Message as BaseMessage;
class Message extends BaseMessage
{
public function isFlagged(): bool
{
return (bool) ($this->meta['flagged'] ?? false);
}
}
Then in config/chat.php:
'models' => [
'message' => \App\Models\Chat\Message::class,
],
use UnseenCodes\Chat\Contracts\ChatManagerContract;
use UnseenCodes\Chat\Contracts\MessageServiceContract;
$chat = app(ChatManagerContract::class);
$msgs = app(MessageServiceContract::class);
$conv = $chat->createPrivateConversation($alice, $bob);
$msgs->send($conv, $alice, 'Hey Bob!');
$msgs->send($conv, $bob, 'Hey Alice!');
MIT © Unseen Codes
How can I help you explore Laravel packages today?