1. Go to this page and download the library: Download asignua/filament-chat library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
asignua / filament-chat example snippets
use Asignua\FilamentChat\FilamentChatPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->databaseNotifications()
->plugin(FilamentChatPlugin::make());
}
FilamentChatPlugin::make()
// Who can be written to and added to groups. Default: everybody in the users table.
->users(fn (Builder $query) => $query->where('is_active', true)->whereHas('roles'))
// How a person is called. Default: users.name_attribute, then Filament's HasName, then `name`.
->userName(fn (User $user): string => "{$user->first_name} {$user->last_name}")
// A person's avatar URL; null — initials. Default: Filament's avatar provider
// (HasAvatar::getFilamentAvatarUrl(), the `avatar_url` attribute, then the panel's default provider).
->avatarUsing(fn (User $user): ?string => $user->profile_photo_url),
// config/filament-chat.php
'users' => [
'model' => null, // null = auth.providers.users.model
'name_attribute' => null, // e.g. 'full_name' — an attribute or accessor
'search_columns' => ['name'], // e.g. ['first_name', 'last_name'] — the conversation search
'broadcast_key' => null, // e.g. 'ulid' — names the private channel (default: the primary key)
],
'messages' => [
'page_size' => 30, // loaded at once and per "Show earlier messages"
'max_length' => 5000,
],
use Asignua\FilamentChat\Support\References\ReferenceType;
FilamentChatPlugin::make()
->references([
ReferenceType::resource(OrderResource::class),
ReferenceType::resource(CustomerResource::class)->color('warning'),
]),
use Asignua\FilamentChat\Data\MessageData;
use Asignua\FilamentChat\Services\ChatService;
$chat = app(ChatService::class);
$conversation = $chat->startDirect($me, $colleague);
$chat->send($conversation, $me, MessageData::fromArray([
'body' => 'Please check @Olga Green',
'reference_type' => 'order',
'reference_id' => $order->id,
]));
// A reply: the ulid of a message in the same conversation (a foreign one is dropped).
$chat->send($conversation, $colleague, MessageData::fromArray([
'body' => 'Done',
'reply_to' => $message->ulid,
]));
use Asignua\FilamentChat\Policies\ConversationPolicy;
abort_unless(Gate::allows('update', $conversation), 403); // the creator, still a member
$chat->updateGroup($conversation, GroupData::fromArray($data));
abort_unless(Gate::allows(ConversationPolicy::LEAVE, $conversation), 403);
$chat->leave($conversation, auth()->user());
FilamentChatPlugin::make()->windowComponent(App\Livewire\MyChatWindow::class); // or ui.window_component