nnixon / laravel-simple-realtime-chat
A simple realtime chat package for Laravel
v1.0.0
2025-03-04 15:17 UTC
Requires
- php: ^8.0
- laravel/framework: ^8.0|^9.0|^10.0
README
A lightweight package for adding realtime chat functionality to your Laravel application.
Features
- One-on-one private conversations
- Group chat support
- Realtime message updates with Pusher
- Read status tracking
- User search functionality
- Responsive UI with TailwindCSS
Requirements
- PHP 8.0+
- Laravel 8.0+
- Pusher account for realtime functionality
Prerequisites
Before installing this package, make sure to set up authentication and required dependencies:
# Install Laravel Breeze for authentication composer require laravel/breeze php artisan breeze:install # Install Pusher PHP Server composer require pusher/pusher-php-server # Install npm dependencies npm install # Install required JavaScript packages npm install lodash laravel-echo pusher-js
Installation
- Install the package via composer:
composer require nnixon/laravel-simple-realtime-chat
- Publish the package files:
php artisan realtime-chat:publish
- Run the migrations:
php artisan migrate
- Uncomment the BroadcastServiceProvider in
config/app.php
:
// Uncomment this line in the providers array App\Providers\BroadcastServiceProvider::class,
- Update your
.env
file with Pusher credentials:
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=your-app-id
PUSHER_APP_KEY=your-app-key
PUSHER_APP_SECRET=your-app-secret
PUSHER_APP_CLUSTER=your-app-cluster
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
- Update your
routes/channels.php
file with the following code:
<?php use App\Models\Conversation; use App\Models\User; use Illuminate\Support\Facades\Broadcast; Broadcast::channel('conversation.{conversationId}', function (User $user, $conversationId) { return $user->conversations->contains(function ($conversation) use ($conversationId) { return $conversation->id == $conversationId; }); });
- Build your frontend assets:
npm run build
Usage
Once installed, you can access the chat interface at:
/conversations
- View all conversations/conversations/{id}
- View a specific conversation/conversations/create-group
- Create a new group conversation
Customization
All views are published to resources/views/realtime-chat
and can be customized to match your application's design.
Controllers, models, and other files are published to their respective directories in your application and can be modified as needed.
License
MIT