Download the PHP package bernskiold/laravel-collaboration without Composer

On this page you can find all versions of the php package bernskiold/laravel-collaboration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-collaboration

Share Eloquent records with other users

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status

The owner of a record can share it with other users. Each user gets a permission: "view" or "edit". The policy of the record controls what each permission lets a user do.

The package has no user interface. It has no views and no components. It gives the data, the rules, the events, the notification and the activity log. Your application has the interface.

What the package does

Installation

Install the package with Composer:

Publish the migration:

Run the migration:

If your application enforces a morph map, add the share model to it:

Make a model shareable

Implement Shareable. Use CanBeShared. Then give the column that keeps the key of the owner:

isOwnedBy() and the ownedBy() scope use this column. If the owner is not in one column, override isOwnedBy() and the ownedBy() scope. Add the #[Scope] attribute to your ownedBy() method. A record without an owner column has no owner.

The package does not share a record with its owner. When you delete a record, the package deletes its shares. A soft-deleted record keeps its shares until you force-delete it.

You can override these methods of the trait:

Method Default
sharePermissions() View and edit. The first permission is the default.
shareableName() The name attribute.
shareableUrl() null. The notification has a link to this URL.
shareNotification() The notification in the configuration.

If sharePermissions() returns one permission, your interface does not ask for a permission:

Use the permissions in a policy

The package does not give access. Your policy reads the shares:

If you eager load the shares, isSharedWith() and permissionFor() use the loaded shares. Then a list does not make one query for each record.

Find records

Each scope accepts a model, a key or null. With null, the scope finds no records. You can give auth()->user() also when nobody is signed in.

The sharedWith() scope uses whereHas(). For this reason, the shares table must be on the same database server as the table of the record.

Change the shares

The person that makes the change is optional. If you do not give this person, the package uses the signed-in user.

shareWith() and stopSharingWith() return a ShareOutcome: Added, Changed, Removed or Unchanged. Use it to tell the user what happened:

syncShares() returns ShareChanges. It has the added, changed and removed permissions, keyed by the key of each person, and all the shares after the change. outcomeFor($person) returns the ShareOutcome of one person.

A permission that the record does not offer causes an InvalidArgumentException. The package does not share a record with its owner or with an unknown user.

Events

Event The package dispatches the event when…
RecordShared A user gets access.
SharePermissionChanged A user with access gets a different permission.
RecordUnshared The package removes the access of a user.

The package dispatches the events after the transaction commits. The events are in the Bernskiold\LaravelCollaboration\Events namespace.

Use the events to refresh your interface. You can also use them to clear caches that use the access of a user.

Notifications

When a user gets access, the package sends the notification from the shareNotification() method of the record. The default notification is SharedWithYou. It is a queued email with a link to shareableUrl().

To send a different notification for one type of record, override the method. Return null to send no notification:

The text of the notification is in lang/en/collaboration.php. To change the text, publish the translations:

To change the notification for all records, set notifications.default in the configuration. The constructor gets the record, the user that shared the record and the permission. To send no notifications, set notifications.enabled to false.

Activity log

If spatie/laravel-activitylog is installed, the package records the changes in the activity log of the record. Each call to SyncShares makes one entry for each type of change. The events of the entries are shared, share-changed and unshared. The people property has the names of the users. The people_ids property has their keys.

ShareActivity::describe($entry) returns a description of an entry, as a verb and an object:

Make your interface

The package has no interface. These helpers keep your components small.

Find the record

A component or an API tool can get the record as a morph type and a key. findShareable() returns the record. It returns null if the type is not a shareable model or if the record does not exist. Then authorize the user:

The method finds the record by its route key. To use a different column, give the field, for example findShareable($type, $id, 'id').

The type can be a morph alias or a class name. In a Livewire component, add #[Locked] to the type and the key. Then the browser cannot change the record after you authorize it.

Find people

PeopleDirectory searches all users by name and email address. The results do not include the owner of the record:

resolve() returns the person for the value that the user selected. The value is a key, or an email address to invite. If the person does not exist, resolve() returns null:

To change the search, extend PeopleDirectory. Then set your class in the people configuration:

Users can also share a record with an email address that has no account. To let them do this, override canInvite() and invite(). If the address has an account, invite() returns that user:

name() returns the name of a person. The activity log and the notification use this name.

Show the permissions

SharePermission has a label and a description from the translations of the package:

Test your application

Share::factory() makes shares for your tests. The factory writes the share directly. It does not record activity, dispatch events or send notifications:

The states are on($record), sharedWith($user), sharedBy($user), view(), edit() and permission($permission). Without sharedWith(), the factory makes a user with the factory of your user model.

Merge two users

HandOverShares moves the shares of one user to a second user. If the two users had access to a record, the second user keeps the larger permission. If the second user is the owner of a record, the package deletes the share on that record.

Some merge tools move all the relations of a user. If you use such a tool, do not add a shares relation to your user model. A direct update can break the unique index of the table.

Stability

These values are kept in your database or in your activity log. They do not change in a minor or a patch release:

Configuration

To change the configuration, publish the configuration file:

Testing

Changelog

Refer to the CHANGELOG for the recent changes.

Contributing

Refer to CONTRIBUTING for the procedure.

Security Vulnerabilities

Refer to our security policy for how to report a security vulnerability.

Credits

License

The MIT License (MIT). Refer to the License File for more information.


All versions of laravel-collaboration with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
illuminate/contracts Version ^12.0 || ^13.0
illuminate/database Version ^12.0 || ^13.0
illuminate/events Version ^12.0 || ^13.0
illuminate/notifications Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bernskiold/laravel-collaboration contains the following files

Loading the files please wait ...