| Install | |
|---|---|
composer require wirelabs/fluxchat |
|
| Latest Version: | v0.2.2 |
| PHP: | ^8.3 |
A beautiful Laravel Livewire chat component built with Flux UI, supporting both standard polling and real-time messaging with Laravel Reverb.
Install via Composer:
composer require wirelabs/fluxchat
Run the installation command:
php artisan fluxchat:install
Run migrations:
php artisan migrate
Add the component to your Blade view:
<livewire:fluxchat :contacts="$contacts" />
Where $contacts is a collection of users/contacts:
// In your controller
$contacts = User::where('id', '!=', auth()->id())->get();
return view('chat', compact('contacts'));
Publish the config file:
php artisan vendor:publish --tag="fluxchat-config"
// config/fluxchat.php
return [
'realtime' => [
'enabled' => env('FLUXCHAT_REALTIME_ENABLED', false),
'auto_refresh_interval' => env('FLUXCHAT_AUTO_REFRESH', 5), // seconds
],
'ui' => [
'theme' => env('FLUXCHAT_THEME', 'dark'),
'avatar_size' => env('FLUXCHAT_AVATAR_SIZE', 'sm'),
],
];
Add to your .env file:
# Standard mode (polling every 5 seconds)
FLUXCHAT_REALTIME_ENABLED=false
FLUXCHAT_AUTO_REFRESH=5
# Real-time mode (requires Reverb)
FLUXCHAT_REALTIME_ENABLED=true
BROADCAST_CONNECTION=reverb
FluxChat supports two modes:
To enable real-time messaging:
php artisan install:broadcasting
.env:FLUXCHAT_REALTIME_ENABLED=true
BROADCAST_CONNECTION=reverb
php artisan reverb:start
<livewire:fluxchat
:contacts="$contacts"
contact-model="App\Models\Contact"
contact-name-field="full_name"
:contact-search-fields="['name', 'email']"
/>
Publish the views to customize:
php artisan vendor:publish --tag="fluxchat-views"
Views will be published to resources/views/vendor/fluxchat/.
Publish language files:
php artisan vendor:publish --tag="fluxchat-lang"
Add your own translations in resources/lang/vendor/fluxchat/.
// In your Livewire component
use Wirelabs\FluxChat\Models\Conversation;
use Wirelabs\FluxChat\Models\Message;
// Create a conversation
$conversation = Conversation::create([
'type' => 'private',
'is_group' => false,
]);
// Add participants
$conversation->addParticipant(auth()->user());
$conversation->addParticipant($contact);
// Send a message
$message = $conversation->messages()->create([
'sendable_id' => auth()->id(),
'sendable_type' => User::class,
'body' => 'Hello!',
'type' => 'text',
]);
Listen to FluxChat events:
// EventServiceProvider
use Wirelabs\FluxChat\Events\MessageSent;
protected $listen = [
MessageSent::class => [
SendMessageNotification::class,
],
];
composer test
| Property | Type | Default | Description |
|---|---|---|---|
contacts |
Collection/Array | [] |
Available contacts |
contactModel |
String | User::class |
Contact model class |
contactNameField |
String | 'name' |
Contact name field |
contactSearchFields |
Array | ['name'] |
Searchable fields |
maxContacts |
Integer | 10 |
Max contacts to show |
messages() - Get all messagesparticipants() - Get all participantsaddParticipant($user) - Add participantmarkAsRead($user) - Mark as readconversation() - Get conversationsendable() - Get senderisEdited() - Check if editedphp artisan reverb:start --debug
php artisan config:show broadcasting.default
FLUXCHAT_AUTO_REFRESH=5
@livewireScripts
Contributions are welcome! Please see CONTRIBUTING.md for details.
The MIT License (MIT). Please see License File for more information.
Made with ❤️ by Wirelabs