Configuration
Behaviour is set in code, usually in AppServiceProvider::boot():
use SolutionForest\Collaboration\Collaboration;
Collaboration::broadcast(); // push changes over Laravel Echo / Reverb
Collaboration::pollEvery(1000); // milliseconds, when nothing is pushed
Collaboration::nameUsersUsing(fn (User $user) => $user->display_name);
Collaboration::giveUsersAvatarsUsing(fn (User $user) => $user->avatar_url);
Collaboration::authorizeUsing(fn (User $user, Model $record, string $ability) => $user->can($ability, $record));
Collaboration::scopeRoomsUsing(fn (?Model $record) => tenant()?->id); // keep tenants apart
Collaboration::audit(); // who changed which field, per minuteDeployment settings live in config/collaboration.php. Publish it with php artisan vendor:publish --tag=collaboration-config, or set the environment variables:
| Setting | Environment variable | Default | What it does |
|---|---|---|---|
path | COLLABORATION_PATH | _collaboration | Where the sync route lives |
middleware | ['web'] | The sync route's middleware. It needs the session. | |
connection | COLLABORATION_CONNECTION | default connection | Where drafts and presence are stored |
table_prefix | COLLABORATION_TABLE_PREFIX | collaboration_ | The tables' prefix |
cache_store | COLLABORATION_CACHE_STORE | default store | Save locks and small counters. Must support locks. |
draft_cache | COLLABORATION_DRAFT_CACHE | on with Redis or Memcached | Answer a poll with nothing new without touching the database |
presence | COLLABORATION_PRESENCE | database | redis for many servers and many people |
presence_timeout | COLLABORATION_PRESENCE_TIMEOUT | 20 | Seconds without a heartbeat before someone disappears |
token_lifetime | COLLABORATION_TOKEN_LIFETIME | 900 | Seconds a page's token is valid. Pages renew it themselves. |
rate_limit | COLLABORATION_RATE_LIMIT | 2400 | Sync requests per user per minute, across their tabs |
Your own design
The package adds one small stylesheet. To style everything yourself, turn it off with Collaboration::withoutStyles(), or withoutStyles() from @solutionforest/laravel-collaboration in JavaScript. Every element keeps a collab- class name to style: collab-avatars, collab-avatar, collab-caret, collab-field-person, collab-comments, collab-history, collab-conflicts and so on.
To draw the faces or the field labels with your own components:
<Avatars form={form}>
{({ shown, more, follow }) => shown.map((person) => <MyAvatar key={person.client} person={person} onClick={() => follow(person.client)} />)}
</Avatars>useCollaboration(), useComments() and useVersions() give the data without any markup.
Pushing changes with Reverb
Polling works everywhere. With Reverb or Pusher set up in Laravel Echo, call Collaboration::broadcast(): edits then arrive as soon as they are stored, not at the next poll. The package registers its private channel, and only people in the room may listen.