Installation
composer require wirelabs/fluxchat
php artisan fluxchat:install
php artisan migrate
Verify the fluxchat table exists in your database.
Basic Blade Integration Add the component to a view with required props:
<livewire:fluxchat :contacts="$contacts" />
Pass a collection of users (e.g., from a controller):
$contacts = User::where('id', '!=', auth()->id())->limit(10)->get();
First Message
Reverb Setup (Optional) If using Reverb:
composer require beyondcode/reverb
php artisan reverb:install
Enable real-time in config/fluxchat.php:
'realtime' => [
'enabled' => true,
'channel' => 'fluxchat',
],
Contact Management
$contacts).
public $contacts;
public function mount() {
$this->contacts = User::active()->get();
}
<input wire:model.debounce.300ms="search" placeholder="Search...">
public $search = '';
public function getContactsProperty() {
return User::where('name', 'like', "%{$this->search}%")
->where('id', '!=', auth()->id())
->get();
}
Message Handling
use App\Models\Message;
use Wirelabs\FluxChat\Livewire\Chat;
class CustomChat extends Chat {
protected function createMessage(array $data) {
$message = Message::create([
'user_id' => auth()->id(),
'contact_id' => $data['contact_id'],
'content' => $data['content'],
'metadata' => $data['metadata'] ?? null,
]);
return $message;
}
}
Register the component in AppServiceProvider:
Livewire::component('fluxchat', \App\Livewire\CustomChat::class);
Reverb Integration
// app/Channels/FluxChatChannel.php
namespace App\Channels;
use BeyondCode\Reverb\Channel;
class FluxChatChannel extends Channel {
public function broadcastOn() {
return 'fluxchat';
}
}
createMessage:
broadcast(new \App\Events\MessageSent($message))->toOthers();
UI Customization
.fluxchat-message {
background: #f0f0f0;
}
<livewire:fluxchat>
<x-fluxchat::message.extra>
<!-- Custom footer per message -->
</x-fluxchat::message.extra>
</livewire:fluxchat>
Authentication
public function mount() {
$this->authId = auth()->id();
}
@auth
<livewire:fluxchat />
@endauth
Database Schema
fluxchat_messages table for custom fields:
Schema::table('fluxchat_messages', function (Blueprint $table) {
$table->json('custom_data')->nullable();
});
Message model to cast the new field:
protected $casts = [
'custom_data' => 'array',
];
Testing
$component = new (new \Wirelabs\FluxChat\Livewire\Chat)->resolveView();
$this->assertViewHas('contacts', $component);
$this->livewire(Chat::class, ['contacts' => $users])
->assertSee('Chat UI');
Reverb Misconfiguration
php artisan reverb:start).fluxchat channel is subscribed in config/reverb.php.FluxChatChannel is registered in AppServiceProvider.Polling vs. Realtime
config/fluxchat.php if using Reverb:
'polling' => [
'enabled' => false,
],
Contact Sync Delays
updated() method to refresh contacts:
public function updatedSearch {
$this->dispatch('refresh-contacts');
}
Flux UI Dependency
wirelabs/flux is installed and published:
composer require wirelabs/flux
php artisan vendor:publish --tag="flux"
Livewire Logs
config/livewire.php:
'log' => env('LIVEWIRE_LOG', true),
storage/logs/livewire.log for component lifecycle events.Reverb Debugging
php artisan reverb:log
Database Queries
fluxchat table.Custom Message Models
Message model by binding it in AppServiceProvider:
FluxChat::setMessageModel(\App\Models\CustomMessage::class);
Event Hooks
MessageSent):
use Wirelabs\FluxChat\Events\MessageSent;
MessageSent::listen(function ($message) {
// Send notification, log, etc.
});
API Endpoints
Route::get('/api/chat/{contact}', function ($contact) {
return FluxChat::getMessagesForContact($contact);
});
Localization
php artisan vendor:publish --tag="fluxchat-lang"
resources/lang/en/fluxchat.php:
return [
'custom_message' => 'Your custom message text',
];
How can I help you explore Laravel packages today?