Skip to content

Configuration ​

Behaviour is set in code, usually in AppServiceProvider::boot():

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

Deployment settings live in config/collaboration.php. Publish it with php artisan vendor:publish --tag=collaboration-config, or set the environment variables:

SettingEnvironment variableDefaultWhat it does
pathCOLLABORATION_PATH_collaborationWhere the sync route lives
middleware['web']The sync route's middleware. It needs the session.
connectionCOLLABORATION_CONNECTIONdefault connectionWhere drafts and presence are stored
table_prefixCOLLABORATION_TABLE_PREFIXcollaboration_The tables' prefix
cache_storeCOLLABORATION_CACHE_STOREdefault storeSave locks and small counters. Must support locks.
draft_cacheCOLLABORATION_DRAFT_CACHEon with Redis or MemcachedAnswer a poll with nothing new without touching the database
presenceCOLLABORATION_PRESENCEdatabaseredis for many servers and many people
presence_timeoutCOLLABORATION_PRESENCE_TIMEOUT20Seconds without a heartbeat before someone disappears
token_lifetimeCOLLABORATION_TOKEN_LIFETIME900Seconds a page's token is valid. Pages renew it themselves.
rate_limitCOLLABORATION_RATE_LIMIT2400Sync 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:

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

Released under the MIT License.