Configuration
Behaviour is set on the plugin, in your panel provider. Every option is optional:
CollaborationPlugin::make()
->liveEditing(fn (?Model $record): bool => ! $record?->is_locked) // live, or merge on save only
->broadcasting() // push changes over Reverb instead of polling
->commentsAndHistory(false) // hide comments & history; or fn (Model $record): bool
->mentionable(fn (Model $record) => User::query()->where('team_id', $record->team_id))
->lockWhileEditing() // fields that can't be live are read-only while someone is in them
->audit() // a per-minute trail of who changed which field
->scopeRoomsUsing(fn () => auth()->user()?->team_id)
->pollingInterval(400)
->avatarLimit(5)
->debug(fn (): bool => app()->isLocal());Per field:
TextInput::make('internal_notes')->collaborative(false); // not live
TextInput::make('seo_title')->collaborative('edit-seo'); // live only for people the Gate ability allows
MyEditor::make('body')->collaborative(adapter: 'my-editor', as: FieldKind::Text); // live through your adapterPresence in a table, and in an edit modal:
$table
->columns([PresenceColumn::make()])
->recordActions([EditAction::make()->collaborate()]);Deployment settings are environment variables, read in config/filament-collaboration.php. For example: FILAMENT_COLLABORATION_PRESENCE (database or redis), FILAMENT_COLLABORATION_CACHE_STORE, FILAMENT_COLLABORATION_PRESENCE_TIMEOUT and FILAMENT_COLLABORATION_TOKEN_LIFETIME. Every option, with its default, is in Configuration.
On the plugin
CollaborationPlugin::make()
->liveEditing(fn (?Model $record): bool => true)
->broadcasting()
->pollingInterval(400)
->avatarLimit(5)
->colors(['#1a73e8', '#d93025', '#188038'])
->scopeRoomsUsing(fn (): mixed => auth()->user()?->team_id)
->presenceRenderHook(PanelsRenderHook::PAGE_HEADER_ACTIONS_BEFORE)
->fieldTypes([new StarRatingType])
->debug(fn (): bool => app()->isLocal())
->reportEditorErrors(fn (): bool => app()->isLocal());| Method | Default | What it does |
|---|---|---|
liveEditing() | on | false, or a closure given the $record: presence and merge on save only |
broadcasting() | off | push changes over Laravel broadcasting; see Reverb |
pollingInterval() | 400 | milliseconds between syncs while working together (at least 200) |
avatarLimit() | 5 | avatars in the header before "+3" |
colors() | 16 colours | each person's colour; white text must be readable on each |
scopeRoomsUsing() | none | separate rooms per team, for tenancy without Filament tenancy |
presenceRenderHook() | header actions | where the avatars render; use one of Filament's page hooks |
fieldTypes() | none | your own field types, tried before the built-in ones; see Extending |
debug() | off | shows CollaborationDebugAction; see Debugging |
commentsAndHistory() | on | false, or a closure given $record and $livewire: no comments and history button, and no posting or restoring; see Comments |
mentionable($users, notify:) | none | who can be @mentioned in comments; see Comments |
reportEditorErrors() | off | logs rich editor errors with their content; see Debugging |
lockWhileEditing() | off | fields that cannot be live are read-only for others while somebody is in them |
audit() | off | keeps a per-minute trail of who changed which field; see Auditing |
In config/filament-collaboration.php
Publish it with php artisan vendor:publish --tag=filament-collaboration-config, or set the environment variables.
| Key | Environment variable | Default | What it does |
|---|---|---|---|
connection | FILAMENT_COLLABORATION_CONNECTION | default connection | where drafts and presence are stored |
cache_store | FILAMENT_COLLABORATION_CACHE_STORE | default store | serialises saves; needs atomic locks, shared by all servers |
presence | FILAMENT_COLLABORATION_PRESENCE | database | where presence is kept: database, or redis |
redis_connection | FILAMENT_COLLABORATION_REDIS_CONNECTION | default | the Redis connection for redis presence |
draft_cache | FILAMENT_COLLABORATION_DRAFT_CACHE | on with a Redis or Memcached cache_store | keeps each draft's head in the cache, so a poll with nothing new reads no draft from the database |
presence_timeout | FILAMENT_COLLABORATION_PRESENCE_TIMEOUT | 20 | seconds without a heartbeat before someone disappears |
compact_after | FILAMENT_COLLABORATION_COMPACT_AFTER | 1800 | seconds before a clean draft's edit history is discarded |
token_lifetime | FILAMENT_COLLABORATION_TOKEN_LIFETIME | 900 | seconds a room token is valid; open pages renew it |
prune_uploads_after | FILAMENT_COLLABORATION_PRUNE_UPLOADS_AFTER | 24 | hours before unsaved images are deleted; null turns it off |
rate_limit | FILAMENT_COLLABORATION_RATE_LIMIT | 2400 | sync requests per user per minute, across their tabs |
Many servers, and presence in Redis
Several application servers can share one database: shared drafts are kept in it, so it does not matter which server a request reaches. Give them a shared cache_store with atomic locks, such as Redis or the database, so saves are serialised across servers.
Presence is a heartbeat from every open tab every few seconds. In the database, that is a small write per heartbeat. For many people, keep it in Redis instead, with no database writes for presence. It uses Laravel's Redis connection, either phpredis or predis:
FILAMENT_COLLABORATION_PRESENCE=redis
FILAMENT_COLLABORATION_REDIS_CONNECTION=defaultNothing else changes. Tabs left behind expire by themselves, and a room nobody is in takes up no space. To keep presence somewhere else, bind your own PresenceRepository. demo/tests/Feature/PresenceRepositoryTest.php lists the behaviour it needs.
Without Reverb, put the cache and sessions in Redis too. Every open tab polls, and most polls find nothing new, because most people on a record are reading. With all three in Redis, such a poll makes one database query: the record itself, which is loaded so your policy can check access again.
FILAMENT_COLLABORATION_PRESENCE=redis # who is here, carets
CACHE_STORE=redis # save locks, and each draft's head
SESSION_DRIVER=redis # every poll reads the sessionWith a Redis or Memcached cache store, each draft's head (its position, version and unsaved fields) is kept in the cache, so a poll that is up to date reads no draft from the database. The draft itself stays in the database. Every change gives the draft a new random token in the cache, so a cached head is never out of date: a lost key costs one database read, never a missed change. Set FILAMENT_COLLABORATION_DRAFT_CACHE=false to turn it off. A cache each server keeps for itself, such as array or file, never turns it on, since another server would not see the token change.
To measure your own setup, run the demo's load test with two servers: SERVERS=2 PRESENCE=redis npm run test:load -- 300 45. Add TRANSPORT=reverb to push over Reverb. It checks that everybody sees everybody across both servers, that every editor ends with the same text, and that no typing is lost. The Load workflow runs it on a CI runner.
Several panels
Add the plugin to each panel that should be live; each panel's settings are its own. A panel without the plugin shows the same resources as usual, with no presence.
People on different panels share a record's room, and so edit it together, when the panels' rooms are scoped the same way: give each panel the same scopeRoomsUsing(), or none. Each page syncs through its own panel's endpoint, {panel}/_collaboration/sync, and a token from one panel is refused on another.
A panel may sign people in with a guard of its own (->authGuard('editors')). The Reverb channel asks every session guard, so whoever is in the room may listen, even when one browser is signed in to two panels as different people.
Laravel Octane
The package runs on Laravel Octane, which keeps the application in memory between requests. It keeps no request's state in static properties or singletons: the push notifier is scoped to the request, and everything else is read again on each one. Register field types with CollaborationPlugin::registerFieldTypes() in a service provider's boot(), which runs once per worker, rather than per request.
Octane workers each have their own memory, so give them a shared cache store, such as Redis, as you would several servers. A cache store each worker keeps for itself, such as array, never turns on the draft cache.
The Octane job runs two editors on a single Swoole worker, so every request goes through the same application: OCTANE=swoole OCTANE_WORKERS=1 npm run test:octane in demo/. OCTANE=swoole npm run test:e2e runs every browser scenario on Octane.
PHPStan
So PHPStan knows about collaborative() and collaborate(), include the extension. With phpstan/extension-installer this happens by itself; otherwise:
includes:
- vendor/solutionforest/filament-collaboration/extension.neon