Skip to content

Configuration ​

Behaviour is set on the plugin, in your panel provider. Every option is optional:

php
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:

php
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 adapter

Presence in a table, and in an edit modal:

php
$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 ​

php
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());
MethodDefaultWhat it does
liveEditing()onfalse, or a closure given the $record: presence and merge on save only
broadcasting()offpush changes over Laravel broadcasting; see Reverb
pollingInterval()400milliseconds between syncs while working together (at least 200)
avatarLimit()5avatars in the header before "+3"
colors()16 colourseach person's colour; white text must be readable on each
scopeRoomsUsing()noneseparate rooms per team, for tenancy without Filament tenancy
presenceRenderHook()header actionswhere the avatars render; use one of Filament's page hooks
fieldTypes()noneyour own field types, tried before the built-in ones; see Extending
debug()offshows CollaborationDebugAction; see Debugging
commentsAndHistory()onfalse, or a closure given $record and $livewire: no comments and history button, and no posting or restoring; see Comments
mentionable($users, notify:)nonewho can be @mentioned in comments; see Comments
reportEditorErrors()offlogs rich editor errors with their content; see Debugging
lockWhileEditing()offfields that cannot be live are read-only for others while somebody is in them
audit()offkeeps 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.

KeyEnvironment variableDefaultWhat it does
connectionFILAMENT_COLLABORATION_CONNECTIONdefault connectionwhere drafts and presence are stored
cache_storeFILAMENT_COLLABORATION_CACHE_STOREdefault storeserialises saves; needs atomic locks, shared by all servers
presenceFILAMENT_COLLABORATION_PRESENCEdatabasewhere presence is kept: database, or redis
redis_connectionFILAMENT_COLLABORATION_REDIS_CONNECTIONdefaultthe Redis connection for redis presence
draft_cacheFILAMENT_COLLABORATION_DRAFT_CACHEon with a Redis or Memcached cache_storekeeps each draft's head in the cache, so a poll with nothing new reads no draft from the database
presence_timeoutFILAMENT_COLLABORATION_PRESENCE_TIMEOUT20seconds without a heartbeat before someone disappears
compact_afterFILAMENT_COLLABORATION_COMPACT_AFTER1800seconds before a clean draft's edit history is discarded
token_lifetimeFILAMENT_COLLABORATION_TOKEN_LIFETIME900seconds a room token is valid; open pages renew it
prune_uploads_afterFILAMENT_COLLABORATION_PRUNE_UPLOADS_AFTER24hours before unsaved images are deleted; null turns it off
rate_limitFILAMENT_COLLABORATION_RATE_LIMIT2400sync 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:

dotenv
FILAMENT_COLLABORATION_PRESENCE=redis
FILAMENT_COLLABORATION_REDIS_CONNECTION=default

Nothing 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.

dotenv
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 session

With 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:

neon
includes:
    - vendor/solutionforest/filament-collaboration/extension.neon

Released under the MIT License.