Installation
composer require aaix/filament-chat-bubbles
Publish the config and migrations:
php artisan vendor:publish --provider="Aaix\FilamentChatBubbles\FilamentChatBubblesServiceProvider" --tag="config"
php artisan vendor:publish --provider="Aaix\FilamentChatBubbles\FilamentChatBubblesServiceProvider" --tag="migrations"
php artisan migrate
Configure Laravel Echo
Ensure your config/filament-chat-bubbles.php is set up with your broadcasting driver (e.g., Pusher, Laravel WebSockets). Example:
'broadcasting' => [
'driver' => env('BROADCAST_DRIVER', 'pusher'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => true,
],
],
Register the Plugin
Add the plugin to your Filament admin panel in app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\Aaix\FilamentChatBubbles\FilamentChatBubblesPlugin::make(),
]);
}
First Use Case: Send a Test Message Use Tinker to create a test user and message:
php artisan tinker
$user = \App\Models\User::first();
$message = \Aaix\FilamentChatBubbles\Models\Message::create([
'user_id' => $user->id,
'content' => 'Hello from Filament Chat Bubbles!',
'is_read' => false,
]);
Sending Messages
Use the sendMessage helper or manually create a Message model. Trigger a broadcast event:
use Aaix\FilamentChatBubbles\Events\MessageSent;
event(new MessageSent($message));
Or use the provided facade:
\Aaix\FilamentChatBubbles\Facades\FilamentChatBubbles::sendMessage($userId, 'Hello!');
Listening for Messages
Subscribe to the message-sent channel in your frontend JavaScript (handled automatically by the package if configured correctly). No manual JS setup is needed beyond Laravel Echo initialization.
attachments relationship:
$message->attachments()->attach([
['fileable_id' => $file->id, 'fileable_type' => \App\Models\File::class],
]);
HasAttachments trait or use a polymorphic relationship.is_online column in the users table (auto-synced via the Presence model). Trigger presence updates:
\Aaix\FilamentChatBubbles\Facades\FilamentChatBubbles::setUserPresence($userId, true);
user-presence-updated events in your frontend.php artisan vendor:publish --provider="Aaix\FilamentChatBubbles\FilamentChatBubblesServiceProvider" --tag="views"
resources/views/vendor/filament-chat-bubbles/bubble.blade.php to change styling or content.Ensure your resources/js/bootstrap.js includes Echo:
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
forceTLS: true,
});
position config option in filament-chat-bubbles.php to place bubbles (e.g., top-right, bottom-left).chatBubbles widget in your Filament panel:
use Aaix\FilamentChatBubbles\Widgets\ChatBubbles;
public function widgets(): array
{
return [
ChatBubbles::make(),
];
}
The package includes API routes for messages and files. Extend them in routes/api.php:
Route::middleware('auth:sanctum')->group(function () {
require __DIR__.'/filament-chat-bubbles.php';
});
Broadcasting Driver Mismatch
.env and config/broadcasting.php.php artisan queue:work if using Redis.CORS Issues
config/cors.php:
'paths' => ['api/*', 'broadcasting/auth', 'echo/*'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'], // Replace with your panel's URL in production
File Attachments Not Showing
Storage facade (e.g., public or s3). Use the url method:
$file->url(); // Returns the accessible URL
Presence Not Updating
Presence model uses Laravel’s online method. Ensure your AppServiceProvider has:
use Laravel\Presence\Presence;
public function boot()
{
Presence::enableForModel(\App\Models\User::class);
}
Check Events Listen for events in Tinker to debug:
\Aaix\FilamentChatBubbles\Events\MessageSent::dispatch($message);
Use php artisan events:listen to see if events are fired.
Log Broadcasts
Add logging to app/Providers/BroadcastServiceProvider.php:
public function boot()
{
\Log::info('Broadcasting event:', ['event' => $event]);
}
Clear Cache If bubbles or messages don’t appear, clear Filament and config caches:
php artisan filament:cache:clear
php artisan config:clear
Custom User Model
Extend the HasPresence trait to your user model:
use Aaix\FilamentChatBubbles\Traits\HasPresence;
class User extends Authenticatable
{
use HasPresence;
}
Message Read Receipts
Use the markAsRead method to update message status:
$message->markAsRead();
Trigger this via a button click in the frontend.
Typing Indicators
Implement a user-typing event to show typing indicators:
\Aaix\FilamentChatBubbles\Facades\FilamentChatBubbles::userIsTyping($userId, true);
Dark Mode Support Override the bubble styles in your Filament theme:
.filament-chat-bubbles-bubble {
background: #333;
color: #fff;
}
Rate Limiting
Add rate limiting to message endpoints in app/Http/Kernel.php:
'throttle:api' => [
\Aaix\FilamentChatBubbles\Http\Controllers\MessageController::class,
],
Localization Publish the language files and translate messages:
php artisan vendor:publish --provider="Aaix\FilamentChatBubbles\FilamentChatBubblesServiceProvider" --tag="lang"
How can I help you explore Laravel packages today?