Download the PHP package cybercog/laravel-ownership without Composer

On this page you can find all versions of the php package cybercog/laravel-ownership. 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-ownership

cog-laravel-ownership

Discord Build StyleCI Releases License

Introduction

Laravel Ownership simplify management of Eloquent model's owner. Group can be an owner of event, user can be an owner of chat room, organization can own licenses. It can be used for many cases not limited by authorship. Make any model as owner and create ownable models in a minutes!

Contents

Features

Installation

First, pull in the package through Composer.

Register Package Manually (optional)

If you disabled package auto-discovery you can register it manually.

Include the service provider within app/config/app.php.

Usage

Laravel Ownership allows model to have strict owner model type (HasOwner trait) or use polymorphic relation (HasMorphOwner trait).

Strict ownership is useful when model can belong to only one model type. Attempt to set owner of not defined model type will throw an exception InvalidOwnerType. Example: Only users allowed to create posts.

Polymorphic ownership is useful when model can belong to owners of different types. Example: Users and Organizations can upload applications to marketplace.

Prepare owner model

At the owner model use CanBeOwner contract and implement it:

Prepare ownable model with strict ownership

Use Ownable contract in model which will get ownership behavior and implement it or just use HasOwner trait.

Ownable model with strict ownership must have in database additional nullable column to store owner relation:

Overwrite strict ownership owner's foreign key

By default, owner model will be the same as config('auth.providers.users.model') provides.

To override default owner model in strict ownership, it's primary key or foreign key extend your ownable model with additional attributes:

Prepare ownable model with polymorphic ownership

Use Ownable contract in model which will get polymorphic ownership behavior and implement it or just use HasMorphOwner trait.

Ownable model with polymorphic ownership must have in database additional nullable columns to store owner relation:

Available methods

Get owner relation

Get model owner

Change (set) owner

Abandon (unset) owner

Check if has owner

Check if owned by owner

Check not owned by owner

Manually define default owner on model creation

Will use resolveDefaultOwner() method under the hood.

Or provide concrete owner:

Skip defining default owner on model creation

Scopes

Scope models by owner

Scope models by not owned by owner

Set authenticated user as owner automatically

To set currently authenticated user as owner for ownable model create - extend it with attribute withDefaultOwnerOnCreate. It works for both strict and polymorphic ownership behavior.

To override strategy of getting default owner extend ownable model with resolveDefaultOwner method:

Changelog

Please see CHANGELOG for more information on what has changed recently.

Upgrading

Please see UPGRADING for detailed upgrade instructions.

Contributing

Please see CONTRIBUTING for details.

Testing

Run the tests with:

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

@antonkomarev
Anton Komarev
@soap
Prasit Gebsaap

Laravel Ownership contributors list

Alternatives

Feel free to add more alternatives as Pull Request.

License

About CyberCog

CyberCog is a Social Unity of enthusiasts. Research the best solutions in product & software development is our passion.

CyberCog


All versions of laravel-ownership with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/database Version ^9.0|^10.0|^11.0
illuminate/support Version ^9.0|^10.0|^11.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 cybercog/laravel-ownership contains the following files

Loading the files please wait ....